@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
@@ -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,11 +29,11 @@ var _fs = require("fs");
|
|
29
29
|
|
30
30
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
31
31
|
|
32
|
-
var _clean = require("
|
32
|
+
var _clean = require("../utils/clean");
|
33
33
|
|
34
|
-
var _utils = require("
|
34
|
+
var _utils = require("../utils");
|
35
35
|
|
36
|
-
var _imports = require("
|
36
|
+
var _imports = require("../utils/imports");
|
37
37
|
|
38
38
|
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); }
|
39
39
|
|
@@ -41,7 +41,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
41
41
|
|
42
42
|
var _default = /*#__PURE__*/function () {
|
43
43
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath) {
|
44
|
-
var Contract, QueryMsg, ExecuteMsg, typeHash, Client, Instance, QueryClient, ReadOnlyInstance, body, children, code;
|
44
|
+
var Contract, QueryMsg, ExecuteMsg, typeHash, Client, Instance, QueryClient, ReadOnlyInstance, body, context, children, code;
|
45
45
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
46
46
|
while (1) {
|
47
47
|
switch (_context.prev = _context.next) {
|
@@ -66,13 +66,14 @@ var _default = /*#__PURE__*/function () {
|
|
66
66
|
body.push((0, _clean.clean)(type));
|
67
67
|
}); // alias the ExecuteMsg
|
68
68
|
|
69
|
-
ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name, "ExecuteMsg")), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
69
|
+
ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name, "ExecuteMsg")), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
70
|
+
context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas)); // query messages
|
70
71
|
|
71
72
|
if (QueryMsg) {
|
72
73
|
QueryClient = (0, _case.pascal)("".concat(name, "QueryClient"));
|
73
74
|
ReadOnlyInstance = (0, _case.pascal)("".concat(name, "ReadOnlyInterface"));
|
74
|
-
body.push(w.createQueryInterface(ReadOnlyInstance, QueryMsg));
|
75
|
-
body.push(w.createQueryClass(QueryClient, ReadOnlyInstance, QueryMsg));
|
75
|
+
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
76
|
+
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
76
77
|
} // execute messages
|
77
78
|
|
78
79
|
|
@@ -82,8 +83,8 @@ var _default = /*#__PURE__*/function () {
|
|
82
83
|
if (children.length > 0) {
|
83
84
|
Client = (0, _case.pascal)("".concat(name, "Client"));
|
84
85
|
Instance = (0, _case.pascal)("".concat(name, "Interface"));
|
85
|
-
body.push(w.createExecuteInterface(Instance, ReadOnlyInstance, ExecuteMsg));
|
86
|
-
body.push(w.createExecuteClass(Client, Instance, QueryClient, ExecuteMsg));
|
86
|
+
body.push(w.createExecuteInterface(context, Instance, ReadOnlyInstance, ExecuteMsg));
|
87
|
+
body.push(w.createExecuteClass(context, Client, Instance, QueryClient, ExecuteMsg));
|
87
88
|
}
|
88
89
|
}
|
89
90
|
|
@@ -91,7 +92,7 @@ var _default = /*#__PURE__*/function () {
|
|
91
92
|
(0, _mkdirp.sync)(outPath);
|
92
93
|
(0, _fs.writeFileSync)((0, _path.join)(outPath, Contract), code);
|
93
94
|
|
94
|
-
case
|
95
|
+
case 21:
|
95
96
|
case "end":
|
96
97
|
return _context.stop();
|
97
98
|
}
|
package/main/index.js
CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
7
7
|
});
|
8
8
|
var _exportNames = {
|
9
|
-
|
9
|
+
tsClient: true,
|
10
10
|
fromPartial: true,
|
11
11
|
reactQuery: true,
|
12
12
|
recoil: true
|
@@ -17,12 +17,6 @@ Object.defineProperty(exports, "fromPartial", {
|
|
17
17
|
return _fromPartial["default"];
|
18
18
|
}
|
19
19
|
});
|
20
|
-
Object.defineProperty(exports, "generate", {
|
21
|
-
enumerable: true,
|
22
|
-
get: function get() {
|
23
|
-
return _generate["default"];
|
24
|
-
}
|
25
|
-
});
|
26
20
|
Object.defineProperty(exports, "reactQuery", {
|
27
21
|
enumerable: true,
|
28
22
|
get: function get() {
|
@@ -35,14 +29,20 @@ Object.defineProperty(exports, "recoil", {
|
|
35
29
|
return _recoil["default"];
|
36
30
|
}
|
37
31
|
});
|
32
|
+
Object.defineProperty(exports, "tsClient", {
|
33
|
+
enumerable: true,
|
34
|
+
get: function get() {
|
35
|
+
return _tsClient["default"];
|
36
|
+
}
|
37
|
+
});
|
38
38
|
|
39
|
-
var
|
39
|
+
var _tsClient = _interopRequireDefault(require("./generators/ts-client"));
|
40
40
|
|
41
|
-
var _fromPartial = _interopRequireDefault(require("./from-partial"));
|
41
|
+
var _fromPartial = _interopRequireDefault(require("./generators/from-partial"));
|
42
42
|
|
43
|
-
var _reactQuery = _interopRequireDefault(require("./react-query"));
|
43
|
+
var _reactQuery = _interopRequireDefault(require("./generators/react-query"));
|
44
44
|
|
45
|
-
var _recoil = _interopRequireDefault(require("./recoil"));
|
45
|
+
var _recoil = _interopRequireDefault(require("./generators/recoil"));
|
46
46
|
|
47
47
|
var _utils = require("./utils");
|
48
48
|
|
@@ -58,7 +58,7 @@ Object.keys(_utils).forEach(function (key) {
|
|
58
58
|
});
|
59
59
|
});
|
60
60
|
|
61
|
-
var _imports = require("./imports");
|
61
|
+
var _imports = require("./utils/imports");
|
62
62
|
|
63
63
|
Object.keys(_imports).forEach(function (key) {
|
64
64
|
if (key === "default" || key === "__esModule") return;
|
File without changes
|
File without changes
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.header = void 0;
|
9
9
|
|
10
|
-
var _package = _interopRequireDefault(require("
|
10
|
+
var _package = _interopRequireDefault(require("../../package.json"));
|
11
11
|
|
12
12
|
var version = process.env.NODE_ENV === 'test' ? 'latest' : _package["default"].version;
|
13
13
|
var header = "/**\n* This file was automatically generated by ".concat(_package["default"].name, "@").concat(version, ".\n* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,\n* and run the ").concat(_package["default"].name, " generate command to regenerate this file.\n*/\n\n");
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _schemas = require("./schemas");
|
8
|
+
|
9
|
+
Object.keys(_schemas).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _schemas[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _schemas[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
File without changes
|
File without changes
|
@@ -0,0 +1,167 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.readSchemas = exports.getDefinitionSchema = exports.findQueryMsg = exports.findExecuteMsg = exports.findAndParseTypes = void 0;
|
9
|
+
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
11
|
+
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
+
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
15
|
+
|
16
|
+
var _glob = require("glob");
|
17
|
+
|
18
|
+
var _fs = require("fs");
|
19
|
+
|
20
|
+
var _cleanse = require("./cleanse");
|
21
|
+
|
22
|
+
var _jsonSchemaToTypescript = require("json-schema-to-typescript");
|
23
|
+
|
24
|
+
var _parse = require("./parse");
|
25
|
+
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
27
|
+
|
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
|
+
|
30
|
+
var readSchemas = /*#__PURE__*/function () {
|
31
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
32
|
+
var schemaDir, argv, _ref$clean, clean, fn, files, schemas;
|
33
|
+
|
34
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
35
|
+
while (1) {
|
36
|
+
switch (_context.prev = _context.next) {
|
37
|
+
case 0:
|
38
|
+
schemaDir = _ref.schemaDir, argv = _ref.argv, _ref$clean = _ref.clean, clean = _ref$clean === void 0 ? true : _ref$clean;
|
39
|
+
fn = clean ? _cleanse.cleanse : function (str) {
|
40
|
+
return str;
|
41
|
+
};
|
42
|
+
files = (0, _glob.sync)(schemaDir + '/**/*.json');
|
43
|
+
schemas = files.map(function (file) {
|
44
|
+
return JSON.parse((0, _fs.readFileSync)(file, 'utf-8'));
|
45
|
+
});
|
46
|
+
|
47
|
+
if (!argv.packed) {
|
48
|
+
_context.next = 8;
|
49
|
+
break;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (!(schemas.length !== 1)) {
|
53
|
+
_context.next = 7;
|
54
|
+
break;
|
55
|
+
}
|
56
|
+
|
57
|
+
throw new Error('packed option only supports one file');
|
58
|
+
|
59
|
+
case 7:
|
60
|
+
return _context.abrupt("return", Object.values(fn(schemas[0])));
|
61
|
+
|
62
|
+
case 8:
|
63
|
+
return _context.abrupt("return", fn(schemas));
|
64
|
+
|
65
|
+
case 9:
|
66
|
+
case "end":
|
67
|
+
return _context.stop();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}, _callee);
|
71
|
+
}));
|
72
|
+
|
73
|
+
return function readSchemas(_x) {
|
74
|
+
return _ref2.apply(this, arguments);
|
75
|
+
};
|
76
|
+
}();
|
77
|
+
|
78
|
+
exports.readSchemas = readSchemas;
|
79
|
+
|
80
|
+
var findQueryMsg = function findQueryMsg(schemas) {
|
81
|
+
var QueryMsg = schemas.find(function (schema) {
|
82
|
+
return schema.title === 'QueryMsg';
|
83
|
+
});
|
84
|
+
return QueryMsg;
|
85
|
+
};
|
86
|
+
|
87
|
+
exports.findQueryMsg = findQueryMsg;
|
88
|
+
|
89
|
+
var findExecuteMsg = function findExecuteMsg(schemas) {
|
90
|
+
var ExecuteMsg = schemas.find(function (schema) {
|
91
|
+
return schema.title === 'ExecuteMsg' || schema.title === 'ExecuteMsg_for_Empty' || // if cleanse is used, this is never
|
92
|
+
schema.title === 'ExecuteMsgForEmpty';
|
93
|
+
});
|
94
|
+
return ExecuteMsg;
|
95
|
+
};
|
96
|
+
|
97
|
+
exports.findExecuteMsg = findExecuteMsg;
|
98
|
+
|
99
|
+
var findAndParseTypes = /*#__PURE__*/function () {
|
100
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(schemas) {
|
101
|
+
var Types, allTypes, typ, _i, _Object$keys, key, result, typeHash;
|
102
|
+
|
103
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
104
|
+
while (1) {
|
105
|
+
switch (_context2.prev = _context2.next) {
|
106
|
+
case 0:
|
107
|
+
Types = schemas;
|
108
|
+
allTypes = [];
|
109
|
+
_context2.t0 = _regenerator["default"].keys(Types);
|
110
|
+
|
111
|
+
case 3:
|
112
|
+
if ((_context2.t1 = _context2.t0()).done) {
|
113
|
+
_context2.next = 12;
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
|
117
|
+
typ = _context2.t1.value;
|
118
|
+
|
119
|
+
if (Types[typ].definitions) {
|
120
|
+
for (_i = 0, _Object$keys = Object.keys(Types[typ].definitions); _i < _Object$keys.length; _i++) {
|
121
|
+
key = _Object$keys[_i];
|
122
|
+
// set title
|
123
|
+
Types[typ].definitions[key].title = key;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
_context2.next = 8;
|
128
|
+
return (0, _jsonSchemaToTypescript.compile)(Types[typ], Types[typ].title);
|
129
|
+
|
130
|
+
case 8:
|
131
|
+
result = _context2.sent;
|
132
|
+
allTypes.push(result);
|
133
|
+
_context2.next = 3;
|
134
|
+
break;
|
135
|
+
|
136
|
+
case 12:
|
137
|
+
typeHash = (0, _parse.parser)(allTypes);
|
138
|
+
return _context2.abrupt("return", typeHash);
|
139
|
+
|
140
|
+
case 14:
|
141
|
+
case "end":
|
142
|
+
return _context2.stop();
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}, _callee2);
|
146
|
+
}));
|
147
|
+
|
148
|
+
return function findAndParseTypes(_x2) {
|
149
|
+
return _ref3.apply(this, arguments);
|
150
|
+
};
|
151
|
+
}();
|
152
|
+
|
153
|
+
exports.findAndParseTypes = findAndParseTypes;
|
154
|
+
|
155
|
+
var getDefinitionSchema = function getDefinitionSchema(schemas) {
|
156
|
+
var aggregateSchema = {
|
157
|
+
definitions: {//
|
158
|
+
}
|
159
|
+
};
|
160
|
+
schemas.forEach(function (schema) {
|
161
|
+
schema.definitions = schema.definitions || {};
|
162
|
+
aggregateSchema.definitions = _objectSpread(_objectSpread({}, aggregateSchema.definitions), schema.definitions);
|
163
|
+
});
|
164
|
+
return aggregateSchema;
|
165
|
+
};
|
166
|
+
|
167
|
+
exports.getDefinitionSchema = getDefinitionSchema;
|
package/module/cli.js
CHANGED
package/module/cmds.js
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
import _boilerplate from './commands/boilerplate';
|
2
1
|
import _from_partial from './commands/from-partial';
|
3
2
|
import _generate from './commands/generate';
|
4
3
|
import _react_query from './commands/react-query';
|
5
4
|
import _recoil from './commands/recoil';
|
6
5
|
const Commands = {};
|
7
|
-
Commands['boilerplate'] = _boilerplate;
|
8
6
|
Commands['from-partial'] = _from_partial;
|
9
7
|
Commands['generate'] = _generate;
|
10
8
|
Commands['react-query'] = _react_query;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { prompt } from '../prompt';
|
2
|
-
import fromPartial from '../from-partial';
|
1
|
+
import { prompt } from '../utils/prompt';
|
2
|
+
import fromPartial from '../generators/from-partial';
|
3
3
|
import { readSchemas } from '../utils';
|
4
4
|
export default (async argv => {
|
5
5
|
const questions = [{
|
@@ -25,7 +25,7 @@ export default (async argv => {
|
|
25
25
|
out,
|
26
26
|
name
|
27
27
|
} = await prompt(questions, argv);
|
28
|
-
const schemas = readSchemas({
|
28
|
+
const schemas = await readSchemas({
|
29
29
|
schemaDir: schema,
|
30
30
|
argv
|
31
31
|
});
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { prompt } from '../prompt';
|
2
|
-
import
|
1
|
+
import { prompt } from '../utils/prompt';
|
2
|
+
import tsClient from '../generators/ts-client';
|
3
3
|
import { readSchemas } from '../utils';
|
4
4
|
export default (async argv => {
|
5
5
|
const questions = [{
|
@@ -25,9 +25,9 @@ export default (async argv => {
|
|
25
25
|
out,
|
26
26
|
name
|
27
27
|
} = await prompt(questions, argv);
|
28
|
-
const schemas = readSchemas({
|
28
|
+
const schemas = await readSchemas({
|
29
29
|
schemaDir: schema,
|
30
30
|
argv
|
31
31
|
});
|
32
|
-
await
|
32
|
+
await tsClient(name, schemas, out);
|
33
33
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2
2
|
const _excluded = ["schema", "out", "name"];
|
3
|
-
import { prompt } from '../prompt';
|
4
|
-
import reactQuery from '../react-query';
|
3
|
+
import { prompt } from '../utils/prompt';
|
4
|
+
import reactQuery from '../generators/react-query';
|
5
5
|
import { readSchemas } from '../utils';
|
6
6
|
export default (async argv => {
|
7
7
|
const questions = [{
|
@@ -46,7 +46,7 @@ export default (async argv => {
|
|
46
46
|
} = _await$prompt,
|
47
47
|
options = _objectWithoutProperties(_await$prompt, _excluded);
|
48
48
|
|
49
|
-
const schemas = readSchemas({
|
49
|
+
const schemas = await readSchemas({
|
50
50
|
schemaDir: schema,
|
51
51
|
argv
|
52
52
|
});
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { prompt } from '../prompt';
|
2
|
-
import recoil from '../recoil';
|
1
|
+
import { prompt } from '../utils/prompt';
|
2
|
+
import recoil from '../generators/recoil';
|
3
3
|
import { readSchemas } from '../utils';
|
4
4
|
export default (async argv => {
|
5
5
|
const questions = [{
|
@@ -25,7 +25,7 @@ export default (async argv => {
|
|
25
25
|
out,
|
26
26
|
name
|
27
27
|
} = await prompt(questions, argv);
|
28
|
-
const schemas = readSchemas({
|
28
|
+
const schemas = await readSchemas({
|
29
29
|
schemaDir: schema,
|
30
30
|
argv
|
31
31
|
});
|
package/module/file.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { pascal } from "case";
|
2
|
-
import { header } from '
|
2
|
+
import { header } from '../utils/header';
|
3
3
|
import { join } from "path";
|
4
4
|
import { sync as mkdirp } from "mkdirp";
|
5
5
|
import * as w from 'wasm-ast-types';
|
@@ -7,7 +7,8 @@ import * as t from '@babel/types';
|
|
7
7
|
import { writeFileSync } from 'fs';
|
8
8
|
import generate from "@babel/generator";
|
9
9
|
import { getMessageProperties } from "wasm-ast-types";
|
10
|
-
import { findAndParseTypes, findExecuteMsg } from "
|
10
|
+
import { findAndParseTypes, findExecuteMsg, getDefinitionSchema } from "../utils";
|
11
|
+
import { RenderContext } from "wasm-ast-types";
|
11
12
|
export default (async (name, schemas, outPath) => {
|
12
13
|
const FromPartialFile = pascal(`${name}Contract`) + '.from-partial.ts';
|
13
14
|
const Contract = pascal(`${name}Contract`) + '.ts';
|
@@ -22,7 +23,8 @@ export default (async (name, schemas, outPath) => {
|
|
22
23
|
body.push(w.importStmt(['Coin'], '@cosmjs/amino'));
|
23
24
|
}
|
24
25
|
|
25
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`.replace(/\.ts$/, '')));
|
26
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`.replace(/\.ts$/, '')));
|
27
|
+
const context = new RenderContext(getDefinitionSchema(schemas)); // execute messages
|
26
28
|
|
27
29
|
if (ExecuteMsg) {
|
28
30
|
const children = getMessageProperties(ExecuteMsg);
|
@@ -30,8 +32,8 @@ export default (async (name, schemas, outPath) => {
|
|
30
32
|
if (children.length > 0) {
|
31
33
|
const TheClass = pascal(`${name}MessageComposer`);
|
32
34
|
const Interface = pascal(`${name}Message`);
|
33
|
-
body.push(w.createFromPartialInterface(Interface, ExecuteMsg));
|
34
|
-
body.push(w.createFromPartialClass(TheClass, Interface, ExecuteMsg));
|
35
|
+
body.push(w.createFromPartialInterface(context, Interface, ExecuteMsg));
|
36
|
+
body.push(w.createFromPartialClass(context, TheClass, Interface, ExecuteMsg));
|
35
37
|
}
|
36
38
|
}
|
37
39
|
|
@@ -1,15 +1,20 @@
|
|
1
1
|
import { pascal } from "case";
|
2
|
-
import { header } from '
|
2
|
+
import { header } from '../utils/header';
|
3
3
|
import { join } from "path";
|
4
4
|
import { sync as mkdirp } from "mkdirp";
|
5
5
|
import * as w from 'wasm-ast-types';
|
6
|
+
import { RenderContext } from 'wasm-ast-types';
|
6
7
|
import * as t from '@babel/types';
|
7
8
|
import { writeFileSync } from 'fs';
|
8
9
|
import generate from "@babel/generator";
|
9
|
-
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '
|
10
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg, getDefinitionSchema } from '../utils';
|
10
11
|
import { getMessageProperties } from "wasm-ast-types";
|
11
|
-
import { cosmjsAminoImportStatements } from '
|
12
|
-
export default (async (contractName, schemas, outPath,
|
12
|
+
import { cosmjsAminoImportStatements } from '../utils/imports';
|
13
|
+
export default (async (contractName, schemas, outPath, reactQueryOptions) => {
|
14
|
+
const context = new RenderContext(getDefinitionSchema(schemas), {
|
15
|
+
reactQuery: reactQueryOptions ?? {}
|
16
|
+
});
|
17
|
+
const options = context.options.reactQuery;
|
13
18
|
const ReactQueryFile = pascal(`${contractName}Contract`) + '.react-query.ts';
|
14
19
|
const Contract = pascal(`${contractName}Contract`);
|
15
20
|
const QueryMsg = findQueryMsg(schemas);
|
@@ -40,19 +45,19 @@ export default (async (contractName, schemas, outPath, options) => {
|
|
40
45
|
|
41
46
|
if (QueryMsg) {
|
42
47
|
[].push.apply(body, w.createReactQueryHooks({
|
48
|
+
context,
|
43
49
|
queryMsg: QueryMsg,
|
44
50
|
contractName: contractName,
|
45
|
-
QueryClient
|
46
|
-
options
|
51
|
+
QueryClient
|
47
52
|
}));
|
48
53
|
}
|
49
54
|
|
50
55
|
if (shouldGenerateMutationHooks) {
|
51
56
|
[].push.apply(body, w.createReactQueryMutationHooks({
|
57
|
+
context,
|
52
58
|
execMsg: ExecuteMsg,
|
53
59
|
contractName: contractName,
|
54
|
-
ExecuteClient
|
55
|
-
options
|
60
|
+
ExecuteClient
|
56
61
|
}));
|
57
62
|
}
|
58
63
|
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { pascal } from "case";
|
2
|
-
import { header } from '
|
2
|
+
import { header } from '../utils/header';
|
3
3
|
import { join } from "path";
|
4
4
|
import { sync as mkdirp } from "mkdirp";
|
5
5
|
import * as w from 'wasm-ast-types';
|
6
6
|
import * as t from '@babel/types';
|
7
7
|
import { writeFileSync } from 'fs';
|
8
8
|
import generate from "@babel/generator";
|
9
|
-
import { findAndParseTypes, findQueryMsg } from "
|
9
|
+
import { findAndParseTypes, findQueryMsg, getDefinitionSchema } from "../utils";
|
10
|
+
import { RenderContext } from "wasm-ast-types";
|
10
11
|
export default (async (name, schemas, outPath) => {
|
11
12
|
const RecoilFile = pascal(`${name}Contract`) + '.recoil.ts';
|
12
13
|
const Contract = pascal(`${name}Contract`) + '.ts';
|
@@ -17,15 +18,16 @@ export default (async (name, schemas, outPath) => {
|
|
17
18
|
const body = [];
|
18
19
|
body.push(w.importStmt(['selectorFamily'], 'recoil'));
|
19
20
|
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
20
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`.replace(/\.ts$/, '')));
|
21
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`.replace(/\.ts$/, '')));
|
22
|
+
const context = new RenderContext(getDefinitionSchema(schemas)); // query messages
|
21
23
|
|
22
24
|
if (QueryMsg) {
|
23
25
|
QueryClient = pascal(`${name}QueryClient`);
|
24
26
|
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
25
27
|
body.push(w.importStmt([QueryClient], `./${Contract}`));
|
26
28
|
body.push(w.createRecoilQueryClientType());
|
27
|
-
body.push(w.createRecoilQueryClient(name, QueryClient));
|
28
|
-
[].push.apply(body, w.createRecoilSelectors(name, QueryClient, QueryMsg));
|
29
|
+
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
30
|
+
[].push.apply(body, w.createRecoilSelectors(context, name, QueryClient, QueryMsg));
|
29
31
|
}
|
30
32
|
|
31
33
|
const code = header + generate(t.program(body)).code;
|
@@ -1,15 +1,16 @@
|
|
1
1
|
import { pascal } from "case";
|
2
|
-
import { header } from '
|
2
|
+
import { header } from '../utils/header';
|
3
3
|
import { join } from "path";
|
4
4
|
import { sync as mkdirp } from "mkdirp";
|
5
5
|
import * as w from 'wasm-ast-types';
|
6
6
|
import * as t from '@babel/types';
|
7
7
|
import { writeFileSync } from 'fs';
|
8
8
|
import generate from "@babel/generator";
|
9
|
-
import { clean } from "
|
9
|
+
import { clean } from "../utils/clean";
|
10
10
|
import { getMessageProperties } from "wasm-ast-types";
|
11
|
-
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '
|
12
|
-
import { cosmjsAminoImportStatements } from '
|
11
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg, getDefinitionSchema } from '../utils';
|
12
|
+
import { cosmjsAminoImportStatements } from '../utils/imports';
|
13
|
+
import { RenderContext } from "wasm-ast-types";
|
13
14
|
export default (async (name, schemas, outPath) => {
|
14
15
|
const Contract = pascal(`${name}Contract`) + '.ts';
|
15
16
|
const QueryMsg = findQueryMsg(schemas);
|
@@ -27,13 +28,14 @@ export default (async (name, schemas, outPath) => {
|
|
27
28
|
body.push(clean(type));
|
28
29
|
}); // alias the ExecuteMsg
|
29
30
|
|
30
|
-
ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
31
|
+
ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
32
|
+
const context = new RenderContext(getDefinitionSchema(schemas)); // query messages
|
31
33
|
|
32
34
|
if (QueryMsg) {
|
33
35
|
QueryClient = pascal(`${name}QueryClient`);
|
34
36
|
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
35
|
-
body.push(w.createQueryInterface(ReadOnlyInstance, QueryMsg));
|
36
|
-
body.push(w.createQueryClass(QueryClient, ReadOnlyInstance, QueryMsg));
|
37
|
+
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
38
|
+
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
37
39
|
} // execute messages
|
38
40
|
|
39
41
|
|
@@ -43,8 +45,8 @@ export default (async (name, schemas, outPath) => {
|
|
43
45
|
if (children.length > 0) {
|
44
46
|
Client = pascal(`${name}Client`);
|
45
47
|
Instance = pascal(`${name}Interface`);
|
46
|
-
body.push(w.createExecuteInterface(Instance, ReadOnlyInstance, ExecuteMsg));
|
47
|
-
body.push(w.createExecuteClass(Client, Instance, QueryClient, ExecuteMsg));
|
48
|
+
body.push(w.createExecuteInterface(context, Instance, ReadOnlyInstance, ExecuteMsg));
|
49
|
+
body.push(w.createExecuteClass(context, Client, Instance, QueryClient, ExecuteMsg));
|
48
50
|
}
|
49
51
|
}
|
50
52
|
|
package/module/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export { default as
|
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';
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './schemas';
|
File without changes
|
File without changes
|