@cosmwasm/ts-codegen 0.6.0 → 0.7.1

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.
Files changed (50) hide show
  1. package/main/cli.js +1 -1
  2. package/main/cmds.js +0 -3
  3. package/main/commands/from-partial.js +9 -5
  4. package/main/commands/generate.js +10 -6
  5. package/main/commands/react-query.js +9 -5
  6. package/main/commands/recoil.js +9 -5
  7. package/main/file.js +1 -1
  8. package/main/{from-partial.js → generators/from-partial.js} +8 -7
  9. package/main/{react-query.js → generators/react-query.js} +16 -12
  10. package/main/{recoil.js → generators/recoil.js} +8 -7
  11. package/main/{generate.js → generators/ts-client.js} +12 -11
  12. package/main/index.js +12 -12
  13. package/main/{clean.js → utils/clean.js} +0 -0
  14. package/main/{cleanse.js → utils/cleanse.js} +0 -0
  15. package/main/{header.js → utils/header.js} +1 -1
  16. package/main/{imports.js → utils/imports.js} +0 -0
  17. package/main/utils/index.js +18 -0
  18. package/main/{parse.js → utils/parse.js} +0 -0
  19. package/main/{prompt.js → utils/prompt.js} +0 -0
  20. package/main/utils/schemas.js +167 -0
  21. package/module/cli.js +1 -1
  22. package/module/cmds.js +0 -2
  23. package/module/commands/from-partial.js +3 -3
  24. package/module/commands/generate.js +4 -4
  25. package/module/commands/react-query.js +3 -3
  26. package/module/commands/recoil.js +3 -3
  27. package/module/file.js +1 -1
  28. package/module/{from-partial.js → generators/from-partial.js} +7 -5
  29. package/module/{react-query.js → generators/react-query.js} +13 -8
  30. package/module/{recoil.js → generators/recoil.js} +7 -5
  31. package/module/{generate.js → generators/ts-client.js} +11 -9
  32. package/module/index.js +5 -5
  33. package/module/{clean.js → utils/clean.js} +0 -0
  34. package/module/{cleanse.js → utils/cleanse.js} +0 -0
  35. package/module/{header.js → utils/header.js} +1 -1
  36. package/module/{imports.js → utils/imports.js} +0 -0
  37. package/module/utils/index.js +1 -0
  38. package/module/{parse.js → utils/parse.js} +0 -0
  39. package/module/{prompt.js → utils/prompt.js} +0 -0
  40. package/module/{utils.js → utils/schemas.js} +18 -1
  41. package/package.json +25 -25
  42. package/types/cleanse.d.ts +1 -0
  43. package/types/imports.d.ts +1 -0
  44. package/types/index.d.ts +1 -1
  45. package/types/react-query.d.ts +1 -1
  46. package/types/ts-codegen.d.ts +2 -0
  47. package/types/utils.d.ts +8 -2
  48. package/main/commands/boilerplate.js +0 -195
  49. package/main/utils.js +0 -123
  50. package/module/commands/boilerplate.js +0 -116
@@ -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
@@ -1,4 +1,4 @@
1
- import { prompt } from './prompt';
1
+ import { prompt } from './utils/prompt';
2
2
  import { Commands as commands } from './cmds';
3
3
  const question = [{
4
4
  _: true,
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 cosmscript from '../generate';
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 cosmscript(name, schemas, out);
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
  #!/usr/bin/env node
2
- import { prompt } from './prompt';
2
+ import { prompt } from './utils/prompt';
3
3
  import { cli } from './cli';
4
4
  import { readFileSync } from 'fs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { pascal } from "case";
2
- import { header } from './header';
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 "./utils";
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$/, ''))); // execute messages
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 './header';
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 './utils';
10
+ import { findAndParseTypes, findExecuteMsg, findQueryMsg, getDefinitionSchema } from '../utils';
10
11
  import { getMessageProperties } from "wasm-ast-types";
11
- import { cosmjsAminoImportStatements } from './imports';
12
- export default (async (contractName, schemas, outPath, options) => {
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 './header';
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 "./utils";
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$/, ''))); // query messages
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 './header';
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 "./clean";
9
+ import { clean } from "../utils/clean";
10
10
  import { getMessageProperties } from "wasm-ast-types";
11
- import { findAndParseTypes, findExecuteMsg, findQueryMsg } from './utils';
12
- import { cosmjsAminoImportStatements } from './imports';
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'))))); // query messages
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 generate } from './generate';
2
- export { default as fromPartial } from './from-partial';
3
- export { default as reactQuery } from './react-query';
4
- export { default as recoil } from './recoil';
1
+ export { default as tsClient } from './generators/ts-client';
2
+ export { default as fromPartial } from './generators/from-partial';
3
+ export { default as reactQuery } from './generators/react-query';
4
+ export { default as recoil } from './generators/recoil';
5
5
  export * from './utils';
6
- export * from './imports';
6
+ export * from './utils/imports';
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import pkg from '../package.json';
1
+ import pkg from '../../package.json';
2
2
  const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
3
3
  export const header = `/**
4
4
  * This file was automatically generated by ${pkg.name}@${version}.
File without changes
@@ -0,0 +1 @@
1
+ export * from './schemas';
File without changes
File without changes
@@ -1,9 +1,15 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ 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; }
4
+
5
+ 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) { _defineProperty(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; }
6
+
1
7
  import { sync as glob } from 'glob';
2
8
  import { readFileSync } from 'fs';
3
9
  import { cleanse } from './cleanse';
4
10
  import { compile } from 'json-schema-to-typescript';
5
11
  import { parser } from './parse';
6
- export const readSchemas = ({
12
+ export const readSchemas = async ({
7
13
  schemaDir,
8
14
  argv,
9
15
  clean = true
@@ -49,4 +55,15 @@ export const findAndParseTypes = async schemas => {
49
55
 
50
56
  const typeHash = parser(allTypes);
51
57
  return typeHash;
58
+ };
59
+ export const getDefinitionSchema = schemas => {
60
+ const aggregateSchema = {
61
+ definitions: {//
62
+ }
63
+ };
64
+ schemas.forEach(schema => {
65
+ schema.definitions = schema.definitions || {};
66
+ aggregateSchema.definitions = _objectSpread(_objectSpread({}, aggregateSchema.definitions), schema.definitions);
67
+ });
68
+ return aggregateSchema;
52
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
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",
@@ -47,50 +47,50 @@
47
47
  "url": "https://github.com/cosmwasm/ts-codegen/issues"
48
48
  },
49
49
  "devDependencies": {
50
- "@babel/cli": "7.17.10",
51
- "@babel/eslint-parser": "^7.18.2",
52
- "@babel/node": "^7.18.5",
53
- "@types/jest": "^28.1.2",
50
+ "@babel/cli": "7.18.10",
51
+ "@babel/eslint-parser": "^7.18.9",
52
+ "@babel/node": "^7.18.10",
53
+ "@types/jest": "^28.1.6",
54
54
  "ast-stringify": "0.1.0",
55
55
  "babel-core": "7.0.0-bridge.0",
56
- "babel-jest": "28.1.1",
56
+ "babel-jest": "28.1.3",
57
57
  "babel-watch": "^7.0.0",
58
58
  "cosmwasm": "1.1.1",
59
59
  "cross-env": "^7.0.2",
60
- "eslint": "8.17.0",
60
+ "eslint": "8.21.0",
61
61
  "eslint-config-prettier": "^8.5.0",
62
- "eslint-plugin-prettier": "^4.0.0",
63
- "jest": "^28.1.1",
62
+ "eslint-plugin-prettier": "^4.2.1",
63
+ "jest": "^28.1.3",
64
64
  "jest-in-case": "^1.0.2",
65
65
  "prettier": "^2.7.1",
66
66
  "regenerator-runtime": "^0.13.7",
67
- "ts-jest": "^28.0.5",
67
+ "ts-jest": "^28.0.7",
68
68
  "typescript": "^4.7.4"
69
69
  },
70
70
  "dependencies": {
71
- "@babel/core": "7.18.5",
72
- "@babel/generator": "7.18.2",
73
- "@babel/parser": "7.18.5",
74
- "@babel/plugin-proposal-class-properties": "7.17.12",
75
- "@babel/plugin-proposal-export-default-from": "7.17.12",
76
- "@babel/plugin-proposal-object-rest-spread": "7.18.0",
77
- "@babel/plugin-transform-runtime": "7.18.5",
78
- "@babel/preset-env": "7.18.2",
79
- "@babel/preset-typescript": "^7.17.12",
80
- "@babel/runtime": "^7.18.3",
81
- "@babel/traverse": "7.18.5",
82
- "@babel/types": "7.18.4",
71
+ "@babel/core": "7.18.10",
72
+ "@babel/generator": "7.18.12",
73
+ "@babel/parser": "7.18.11",
74
+ "@babel/plugin-proposal-class-properties": "7.18.6",
75
+ "@babel/plugin-proposal-export-default-from": "7.18.10",
76
+ "@babel/plugin-proposal-object-rest-spread": "7.18.9",
77
+ "@babel/plugin-transform-runtime": "7.18.10",
78
+ "@babel/preset-env": "7.18.10",
79
+ "@babel/preset-typescript": "^7.18.6",
80
+ "@babel/runtime": "^7.18.9",
81
+ "@babel/traverse": "7.18.11",
82
+ "@babel/types": "7.18.10",
83
83
  "case": "1.6.3",
84
84
  "dargs": "7.0.0",
85
85
  "fuzzy": "0.1.3",
86
86
  "glob": "8.0.3",
87
87
  "inquirerer": "0.1.3",
88
- "json-schema-to-typescript": "10.1.5",
88
+ "json-schema-to-typescript": "11.0.1",
89
89
  "long": "^5.2.0",
90
90
  "minimist": "1.2.6",
91
91
  "mkdirp": "1.0.4",
92
92
  "shelljs": "0.8.5",
93
- "wasm-ast-types": "^0.5.0"
93
+ "wasm-ast-types": "^0.6.0"
94
94
  },
95
- "gitHead": "871479982969e89f40b75ca5c85e8bed34a824da"
95
+ "gitHead": "103ec48e18ab5bd88329ec36b558e5caeb79f4b9"
96
96
  }
@@ -0,0 +1 @@
1
+ export declare const cleanse: (obj: any) => any;
@@ -0,0 +1 @@
1
+ export declare const cosmjsAminoImportStatements: (typeHash: any) => any;
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
-
2
1
  export { default as generate } from './generate';
3
2
  export { default as fromPartial } from './from-partial';
4
3
  export { default as reactQuery } from './react-query';
5
4
  export { default as recoil } from './recoil';
6
5
  export * from './utils';
6
+ export * from './imports';
@@ -1,2 +1,2 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string, options?: { optionalClient?: boolean, v4?: boolean, mutations?: boolean }) => Promise<void>;
1
+ declare const _default: (contractName: string, schemas: any[], outPath: string, reactQueryOptions?: ReactQueryOptions) => Promise<void>;
2
2
  export default _default;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/types/utils.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export declare const readSchemas: ({ schemaDir, argv }: {
1
+ import { JSONSchema } from 'wasm-ast-types';
2
+ export declare const readSchemas: ({ schemaDir, argv, clean }: {
2
3
  schemaDir: any;
3
4
  argv: any;
4
- }) => any[];
5
+ clean?: boolean;
6
+ }) => Promise<any>;
7
+ export declare const findQueryMsg: (schemas: any) => any;
8
+ export declare const findExecuteMsg: (schemas: any) => any;
9
+ export declare const findAndParseTypes: (schemas: any) => Promise<{}>;
10
+ export declare const getDefinitionSchema: (schemas: JSONSchema[]) => JSONSchema;