@cosmwasm/ts-codegen 0.7.3 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/README.md +238 -59
  2. package/main/builder/builder.js +456 -0
  3. package/main/builder/index.js +18 -0
  4. package/main/bundler/bundler.js +74 -0
  5. package/main/bundler/index.js +18 -0
  6. package/main/cmds.js +3 -9
  7. package/main/commands/create-boilerplate.js +195 -0
  8. package/main/commands/generate.js +91 -16
  9. package/main/generators/{ts-client.js → client.js} +29 -23
  10. package/main/generators/{from-partial.js → message-composer.js} +29 -21
  11. package/main/generators/react-query.js +27 -21
  12. package/main/generators/recoil.js +31 -15
  13. package/main/generators/types.js +95 -0
  14. package/main/index.js +71 -17
  15. package/main/types.js +1 -0
  16. package/main/utils/schemas.js +5 -3
  17. package/module/builder/builder.js +178 -0
  18. package/module/builder/index.js +1 -0
  19. package/module/bundler/bundler.js +36 -0
  20. package/module/bundler/index.js +1 -0
  21. package/module/cmds.js +2 -6
  22. package/module/commands/create-boilerplate.js +116 -0
  23. package/module/commands/generate.js +82 -8
  24. package/module/generators/{ts-client.js → client.js} +21 -15
  25. package/module/generators/{from-partial.js → message-composer.js} +23 -17
  26. package/module/generators/react-query.js +20 -15
  27. package/module/generators/recoil.js +23 -9
  28. package/module/generators/types.js +40 -0
  29. package/module/index.js +12 -5
  30. package/module/types.js +1 -0
  31. package/module/utils/schemas.js +3 -2
  32. package/package.json +5 -3
  33. package/types/builder/builder.d.ts +39 -0
  34. package/types/builder/index.d.ts +1 -0
  35. package/types/bundler/bundler.d.ts +4 -0
  36. package/types/bundler/index.d.ts +1 -0
  37. package/types/commands/{from-partial.d.ts → client.d.ts} +0 -0
  38. package/types/commands/message-composer.d.ts +2 -0
  39. package/types/commands/types.d.ts +2 -0
  40. package/types/generators/client.d.ts +3 -0
  41. package/types/generators/message-composer.d.ts +3 -0
  42. package/types/generators/react-query.d.ts +2 -1
  43. package/types/generators/recoil.d.ts +2 -1
  44. package/types/generators/types.d.ts +3 -0
  45. package/types/index.d.ts +10 -5
  46. package/types/types.d.ts +1 -0
  47. package/types/utils/schemas.d.ts +8 -4
  48. package/main/commands/from-partial.js +0 -78
  49. package/main/commands/react-query.js +0 -98
  50. package/main/commands/recoil.js +0 -78
  51. package/main/utils/imports.js +0 -26
  52. package/module/commands/from-partial.js +0 -33
  53. package/module/commands/react-query.js +0 -54
  54. package/module/commands/recoil.js +0 -33
  55. package/module/utils/imports.js +0 -10
  56. package/types/clean.d.ts +0 -1
  57. package/types/cleanse.d.ts +0 -1
  58. package/types/commands/boilerplate.d.ts +0 -2
  59. package/types/cosmwasm-typescript-gen.d.ts +0 -2
  60. package/types/from-partial.d.ts +0 -2
  61. package/types/generate.d.ts +0 -2
  62. package/types/generators/from-partial.d.ts +0 -2
  63. package/types/generators/ts-client.d.ts +0 -2
  64. package/types/header.d.ts +0 -1
  65. package/types/imports.d.ts +0 -1
  66. package/types/parse.d.ts +0 -1
  67. package/types/prompt.d.ts +0 -3
  68. package/types/react-query.d.ts +0 -2
  69. package/types/recoil.d.ts +0 -2
  70. package/types/utils/imports.d.ts +0 -1
  71. package/types/utils.d.ts +0 -10
package/types/index.d.ts CHANGED
@@ -1,6 +1,11 @@
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';
1
+ import { TSBuilderInput } from './builder';
2
+ export { default as generateTypes } from './generators/types';
3
+ export { default as generateClient } from './generators/client';
4
+ export { default as generateMessageComposer } from './generators/message-composer';
5
+ export { default as generateReactQuery } from './generators/react-query';
6
+ export { default as generateRecoil } from './generators/recoil';
5
7
  export * from './utils';
6
- export * from './utils/imports';
8
+ export * from './builder';
9
+ export * from './bundler';
10
+ declare const _default: (input: TSBuilderInput) => Promise<void>;
11
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,14 @@
1
1
  import { JSONSchema } from 'wasm-ast-types';
2
- export declare const readSchemas: ({ schemaDir, argv, clean }: {
3
- schemaDir: any;
4
- argv: any;
2
+ interface ReadSchemaOpts {
3
+ schemaDir: string;
4
+ schemaOptions?: {
5
+ packed?: boolean;
6
+ };
5
7
  clean?: boolean;
6
- }) => Promise<any>;
8
+ }
9
+ export declare const readSchemas: ({ schemaDir, schemaOptions, clean }: ReadSchemaOpts) => Promise<any>;
7
10
  export declare const findQueryMsg: (schemas: any) => any;
8
11
  export declare const findExecuteMsg: (schemas: any) => any;
9
12
  export declare const findAndParseTypes: (schemas: any) => Promise<{}>;
10
13
  export declare const getDefinitionSchema: (schemas: JSONSchema[]) => JSONSchema;
14
+ export {};
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _prompt = require("../utils/prompt");
15
-
16
- var _fromPartial = _interopRequireDefault(require("../generators/from-partial"));
17
-
18
- var _utils = require("../utils");
19
-
20
- var _default = /*#__PURE__*/function () {
21
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(argv) {
22
- var questions, _yield$prompt, schema, out, name, schemas;
23
-
24
- return _regenerator["default"].wrap(function _callee$(_context) {
25
- while (1) {
26
- switch (_context.prev = _context.next) {
27
- case 0:
28
- questions = [{
29
- _: true,
30
- type: 'path',
31
- name: 'schema',
32
- message: 'which directory contains the the Rust contracts?',
33
- "default": './schema'
34
- }, {
35
- _: true,
36
- type: 'path',
37
- name: 'out',
38
- message: 'where is the output directory?',
39
- "default": './ts'
40
- }, {
41
- _: true,
42
- type: 'string',
43
- name: 'name',
44
- message: 'contract name?'
45
- }];
46
- _context.next = 3;
47
- return (0, _prompt.prompt)(questions, argv);
48
-
49
- case 3:
50
- _yield$prompt = _context.sent;
51
- schema = _yield$prompt.schema;
52
- out = _yield$prompt.out;
53
- name = _yield$prompt.name;
54
- _context.next = 9;
55
- return (0, _utils.readSchemas)({
56
- schemaDir: schema,
57
- argv: argv
58
- });
59
-
60
- case 9:
61
- schemas = _context.sent;
62
- _context.next = 12;
63
- return (0, _fromPartial["default"])(name, schemas, out);
64
-
65
- case 12:
66
- case "end":
67
- return _context.stop();
68
- }
69
- }
70
- }, _callee);
71
- }));
72
-
73
- return function (_x) {
74
- return _ref.apply(this, arguments);
75
- };
76
- }();
77
-
78
- exports["default"] = _default;
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
-
14
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
- var _prompt = require("../utils/prompt");
17
-
18
- var _reactQuery = _interopRequireDefault(require("../generators/react-query"));
19
-
20
- var _utils = require("../utils");
21
-
22
- var _excluded = ["schema", "out", "name"];
23
-
24
- var _default = /*#__PURE__*/function () {
25
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(argv) {
26
- var questions, _yield$prompt, schema, out, name, options, schemas;
27
-
28
- return _regenerator["default"].wrap(function _callee$(_context) {
29
- while (1) {
30
- switch (_context.prev = _context.next) {
31
- case 0:
32
- questions = [{
33
- _: true,
34
- type: 'path',
35
- name: 'schema',
36
- message: 'which directory contains the the Rust contracts?',
37
- "default": './schema'
38
- }, {
39
- _: true,
40
- type: 'path',
41
- name: 'out',
42
- message: 'where is the output directory?',
43
- "default": './ts'
44
- }, {
45
- _: true,
46
- type: 'string',
47
- name: 'name',
48
- message: 'contract name?'
49
- }, {
50
- type: 'confirm',
51
- name: 'optionalClient',
52
- message: 'optionalClient?',
53
- "default": false
54
- }, {
55
- type: 'confirm',
56
- name: 'v4',
57
- message: 'Use react-query v4?',
58
- "default": false
59
- }, {
60
- type: 'confirm',
61
- name: 'mutations',
62
- message: 'Geneate useMutation hooks? Must be used with v4.',
63
- "default": false
64
- }];
65
- _context.next = 3;
66
- return (0, _prompt.prompt)(questions, argv);
67
-
68
- case 3:
69
- _yield$prompt = _context.sent;
70
- schema = _yield$prompt.schema;
71
- out = _yield$prompt.out;
72
- name = _yield$prompt.name;
73
- options = (0, _objectWithoutProperties2["default"])(_yield$prompt, _excluded);
74
- _context.next = 10;
75
- return (0, _utils.readSchemas)({
76
- schemaDir: schema,
77
- argv: argv
78
- });
79
-
80
- case 10:
81
- schemas = _context.sent;
82
- _context.next = 13;
83
- return (0, _reactQuery["default"])(name, schemas, out, options);
84
-
85
- case 13:
86
- case "end":
87
- return _context.stop();
88
- }
89
- }
90
- }, _callee);
91
- }));
92
-
93
- return function (_x) {
94
- return _ref.apply(this, arguments);
95
- };
96
- }();
97
-
98
- exports["default"] = _default;
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _prompt = require("../utils/prompt");
15
-
16
- var _recoil = _interopRequireDefault(require("../generators/recoil"));
17
-
18
- var _utils = require("../utils");
19
-
20
- var _default = /*#__PURE__*/function () {
21
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(argv) {
22
- var questions, _yield$prompt, schema, out, name, schemas;
23
-
24
- return _regenerator["default"].wrap(function _callee$(_context) {
25
- while (1) {
26
- switch (_context.prev = _context.next) {
27
- case 0:
28
- questions = [{
29
- _: true,
30
- type: 'path',
31
- name: 'schema',
32
- message: 'which directory contains the the Rust contracts?',
33
- "default": './schema'
34
- }, {
35
- _: true,
36
- type: 'path',
37
- name: 'out',
38
- message: 'where is the output directory?',
39
- "default": './ts'
40
- }, {
41
- _: true,
42
- type: 'string',
43
- name: 'name',
44
- message: 'contract name?'
45
- }];
46
- _context.next = 3;
47
- return (0, _prompt.prompt)(questions, argv);
48
-
49
- case 3:
50
- _yield$prompt = _context.sent;
51
- schema = _yield$prompt.schema;
52
- out = _yield$prompt.out;
53
- name = _yield$prompt.name;
54
- _context.next = 9;
55
- return (0, _utils.readSchemas)({
56
- schemaDir: schema,
57
- argv: argv
58
- });
59
-
60
- case 9:
61
- schemas = _context.sent;
62
- _context.next = 12;
63
- return (0, _recoil["default"])(name, schemas, out);
64
-
65
- case 12:
66
- case "end":
67
- return _context.stop();
68
- }
69
- }
70
- }, _callee);
71
- }));
72
-
73
- return function (_x) {
74
- return _ref.apply(this, arguments);
75
- };
76
- }();
77
-
78
- exports["default"] = _default;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.cosmjsAminoImportStatements = void 0;
9
-
10
- var w = _interopRequireWildcard(require("wasm-ast-types"));
11
-
12
- 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); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- var cosmjsAminoImportStatements = function cosmjsAminoImportStatements(typeHash) {
17
- var cosmjsImports = ['StdFee']; // If the coin is not provided by the generation already, import it from cosmjs
18
-
19
- if (!typeHash.hasOwnProperty('Coin')) {
20
- cosmjsImports.unshift('Coin');
21
- }
22
-
23
- return w.importStmt(cosmjsImports, '@cosmjs/amino');
24
- };
25
-
26
- exports.cosmjsAminoImportStatements = cosmjsAminoImportStatements;
@@ -1,33 +0,0 @@
1
- import { prompt } from '../utils/prompt';
2
- import fromPartial from '../generators/from-partial';
3
- import { readSchemas } from '../utils';
4
- export default (async argv => {
5
- const questions = [{
6
- _: true,
7
- type: 'path',
8
- name: 'schema',
9
- message: 'which directory contains the the Rust contracts?',
10
- default: './schema'
11
- }, {
12
- _: true,
13
- type: 'path',
14
- name: 'out',
15
- message: 'where is the output directory?',
16
- default: './ts'
17
- }, {
18
- _: true,
19
- type: 'string',
20
- name: 'name',
21
- message: 'contract name?'
22
- }];
23
- const {
24
- schema,
25
- out,
26
- name
27
- } = await prompt(questions, argv);
28
- const schemas = await readSchemas({
29
- schemaDir: schema,
30
- argv
31
- });
32
- await fromPartial(name, schemas, out);
33
- });
@@ -1,54 +0,0 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["schema", "out", "name"];
3
- import { prompt } from '../utils/prompt';
4
- import reactQuery from '../generators/react-query';
5
- import { readSchemas } from '../utils';
6
- export default (async argv => {
7
- const questions = [{
8
- _: true,
9
- type: 'path',
10
- name: 'schema',
11
- message: 'which directory contains the the Rust contracts?',
12
- default: './schema'
13
- }, {
14
- _: true,
15
- type: 'path',
16
- name: 'out',
17
- message: 'where is the output directory?',
18
- default: './ts'
19
- }, {
20
- _: true,
21
- type: 'string',
22
- name: 'name',
23
- message: 'contract name?'
24
- }, {
25
- type: 'confirm',
26
- name: 'optionalClient',
27
- message: 'optionalClient?',
28
- default: false
29
- }, {
30
- type: 'confirm',
31
- name: 'v4',
32
- message: 'Use react-query v4?',
33
- default: false
34
- }, {
35
- type: 'confirm',
36
- name: 'mutations',
37
- message: 'Geneate useMutation hooks? Must be used with v4.',
38
- default: false
39
- }];
40
-
41
- const _await$prompt = await prompt(questions, argv),
42
- {
43
- schema,
44
- out,
45
- name
46
- } = _await$prompt,
47
- options = _objectWithoutProperties(_await$prompt, _excluded);
48
-
49
- const schemas = await readSchemas({
50
- schemaDir: schema,
51
- argv
52
- });
53
- await reactQuery(name, schemas, out, options);
54
- });
@@ -1,33 +0,0 @@
1
- import { prompt } from '../utils/prompt';
2
- import recoil from '../generators/recoil';
3
- import { readSchemas } from '../utils';
4
- export default (async argv => {
5
- const questions = [{
6
- _: true,
7
- type: 'path',
8
- name: 'schema',
9
- message: 'which directory contains the the Rust contracts?',
10
- default: './schema'
11
- }, {
12
- _: true,
13
- type: 'path',
14
- name: 'out',
15
- message: 'where is the output directory?',
16
- default: './ts'
17
- }, {
18
- _: true,
19
- type: 'string',
20
- name: 'name',
21
- message: 'contract name?'
22
- }];
23
- const {
24
- schema,
25
- out,
26
- name
27
- } = await prompt(questions, argv);
28
- const schemas = await readSchemas({
29
- schemaDir: schema,
30
- argv
31
- });
32
- await recoil(name, schemas, out);
33
- });
@@ -1,10 +0,0 @@
1
- import * as w from 'wasm-ast-types';
2
- export const cosmjsAminoImportStatements = typeHash => {
3
- const cosmjsImports = ['StdFee']; // If the coin is not provided by the generation already, import it from cosmjs
4
-
5
- if (!typeHash.hasOwnProperty('Coin')) {
6
- cosmjsImports.unshift('Coin');
7
- }
8
-
9
- return w.importStmt(cosmjsImports, '@cosmjs/amino');
10
- };
package/types/clean.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const clean: (obj: any) => any;
@@ -1 +0,0 @@
1
- export declare const cleanse: (obj: any) => any;
@@ -1,2 +0,0 @@
1
- declare const _default: (argv: any) => Promise<any>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
- export default _default;
package/types/header.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const header: string;
@@ -1 +0,0 @@
1
- export declare const cosmjsAminoImportStatements: (typeHash: any) => any;
package/types/parse.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const parser: (codes: any) => {};
package/types/prompt.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export function getFuzzySearch(list: any): (answers: any, input: any) => Promise<any>;
2
- export function getFuzzySearchNames(nameValueItemList: any): (answers: any, input: any) => Promise<any>;
3
- export function prompt(questions?: any[], argv?: {}): Promise<any>;
@@ -1,2 +0,0 @@
1
- declare const _default: (contractName: string, schemas: any[], outPath: string, reactQueryOptions?: ReactQueryOptions) => Promise<void>;
2
- export default _default;
package/types/recoil.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
2
- export default _default;
@@ -1 +0,0 @@
1
- export declare const cosmjsAminoImportStatements: (typeHash: any) => any;
package/types/utils.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { JSONSchema } from 'wasm-ast-types';
2
- export declare const readSchemas: ({ schemaDir, argv, clean }: {
3
- schemaDir: any;
4
- argv: 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;