wasm-ast-types 0.5.0 → 0.6.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 (93) hide show
  1. package/main/{wasm.js → client/client.js} +54 -40
  2. package/main/client/index.js +18 -0
  3. package/main/client/test/ts-client.arrays.spec.js +25 -0
  4. package/main/client/test/ts-client.cw-named-groups.test.js +25 -0
  5. package/main/client/test/ts-client.cw-proposal-single.test.js +30 -0
  6. package/main/client/test/ts-client.empty-enums.spec.js +19 -0
  7. package/main/client/test/ts-client.sg721.spec.js +25 -0
  8. package/main/client/test/ts-client.spec.js +106 -0
  9. package/main/client/test/ts-client.vectis.spec.js +56 -0
  10. package/main/context/context.js +48 -0
  11. package/main/context/index.js +18 -0
  12. package/main/{messages.js → from-partial/from-partial.js} +17 -60
  13. package/main/from-partial/from-partial.spec.js +20 -0
  14. package/main/from-partial/index.js +18 -0
  15. package/main/index.js +34 -8
  16. package/main/react-query/index.js +18 -0
  17. package/main/{react-query.js → react-query/react-query.js} +39 -64
  18. package/main/{react-query.spec.js → react-query/react-query.spec.js} +33 -43
  19. package/main/recoil/index.js +18 -0
  20. package/main/{recoil.js → recoil/recoil.js} +7 -26
  21. package/main/{recoil.spec.js → recoil/recoil.spec.js} +9 -14
  22. package/main/utils/babel.spec.js +7 -15
  23. package/main/utils/index.js +13 -0
  24. package/main/utils/types.js +35 -33
  25. package/module/{wasm.js → client/client.js} +43 -33
  26. package/module/client/index.js +1 -0
  27. package/module/client/test/ts-client.arrays.spec.js +17 -0
  28. package/module/client/test/ts-client.cw-named-groups.test.js +17 -0
  29. package/module/client/test/ts-client.cw-proposal-single.test.js +21 -0
  30. package/module/client/test/ts-client.empty-enums.spec.js +11 -0
  31. package/module/client/test/ts-client.sg721.spec.js +17 -0
  32. package/module/client/test/ts-client.spec.js +85 -0
  33. package/module/client/test/ts-client.vectis.spec.js +44 -0
  34. package/module/context/context.js +25 -0
  35. package/module/context/index.js +1 -0
  36. package/module/{messages.js → from-partial/from-partial.js} +16 -57
  37. package/module/from-partial/from-partial.spec.js +12 -0
  38. package/module/from-partial/index.js +1 -0
  39. package/module/index.js +5 -3
  40. package/module/react-query/index.js +1 -0
  41. package/module/{react-query.js → react-query/react-query.js} +30 -49
  42. package/module/react-query/react-query.spec.js +53 -0
  43. package/module/recoil/index.js +1 -0
  44. package/module/{recoil.js → recoil/recoil.js} +6 -20
  45. package/module/recoil/recoil.spec.js +15 -0
  46. package/module/utils/babel.spec.js +1 -10
  47. package/module/utils/index.js +2 -1
  48. package/module/utils/types.js +33 -31
  49. package/package.json +26 -24
  50. package/types/src/client/client.d.ts +17 -0
  51. package/types/src/client/index.d.ts +1 -0
  52. package/types/src/client/test/ts-client.cw-named-groups.test.d.ts +1 -0
  53. package/types/src/client/test/ts-client.cw-proposal-single.test.d.ts +1 -0
  54. package/types/src/context/context.d.ts +20 -0
  55. package/types/src/context/index.d.ts +1 -0
  56. package/types/src/from-partial/from-partial.d.ts +4 -0
  57. package/types/src/from-partial/index.d.ts +1 -0
  58. package/types/src/index.d.ts +7 -0
  59. package/types/src/react-query/index.d.ts +1 -0
  60. package/types/src/react-query/react-query.d.ts +81 -0
  61. package/types/src/recoil/index.d.ts +1 -0
  62. package/types/{recoil.d.ts → src/recoil/recoil.d.ts} +5 -5
  63. package/types/{types.d.ts → src/types.d.ts} +17 -0
  64. package/types/{utils.d.ts → src/utils/babel.d.ts} +21 -1
  65. package/types/src/utils/index.d.ts +2 -0
  66. package/types/src/utils/types.d.ts +18 -0
  67. package/types/test-utils/index.d.ts +2 -0
  68. package/main/messages.spec.js +0 -24
  69. package/main/wasm.arrays.spec.js +0 -30
  70. package/main/wasm.cw-named-groups.test.js +0 -30
  71. package/main/wasm.cw-proposal-single.test.js +0 -32
  72. package/main/wasm.empty-enums.spec.js +0 -24
  73. package/main/wasm.sg721.spec.js +0 -30
  74. package/main/wasm.spec.js +0 -95
  75. package/main/wasm.vectis.spec.js +0 -53
  76. package/module/messages.spec.js +0 -18
  77. package/module/react-query.spec.js +0 -65
  78. package/module/recoil.spec.js +0 -22
  79. package/module/wasm.arrays.spec.js +0 -24
  80. package/module/wasm.cw-named-groups.test.js +0 -24
  81. package/module/wasm.cw-proposal-single.test.js +0 -25
  82. package/module/wasm.empty-enums.spec.js +0 -18
  83. package/module/wasm.sg721.spec.js +0 -24
  84. package/module/wasm.spec.js +0 -76
  85. package/module/wasm.vectis.spec.js +0 -43
  86. package/types/amino/amino-interfaces.d.ts +0 -6
  87. package/types/amino/from-amino.d.ts +0 -13
  88. package/types/amino/index.d.ts +0 -3
  89. package/types/amino/to-amino.d.ts +0 -11
  90. package/types/index.d.ts +0 -5
  91. package/types/messages.d.ts +0 -4
  92. package/types/react-query.d.ts +0 -70
  93. package/types/wasm.d.ts +0 -24
@@ -5,51 +5,32 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.createWasmRecoilMethod = exports.createRecoilSelectors = exports.createRecoilSelector = exports.createRecoilQueryClientType = exports.createRecoilQueryClient = void 0;
8
+ exports.createRecoilSelectors = exports.createRecoilSelector = exports.createRecoilQueryClientType = exports.createRecoilQueryClient = void 0;
9
9
 
10
10
  var t = _interopRequireWildcard(require("@babel/types"));
11
11
 
12
12
  var _case = require("case");
13
13
 
14
- var _utils = require("./utils");
14
+ var _utils = require("../utils");
15
15
 
16
16
  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); }
17
17
 
18
18
  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; }
19
19
 
20
- var createWasmRecoilMethod = function createWasmRecoilMethod(jsonschema) {
21
- var _jsonschema$propertie;
22
-
23
- var underscoreName = Object.keys(jsonschema.properties)[0];
24
- var methodName = (0, _case.camel)(underscoreName);
25
- var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
26
- var properties = (_jsonschema$propertie = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {};
27
-
28
- if (Object.keys(properties).length > 0) {} else {}
29
- };
30
-
31
- exports.createWasmRecoilMethod = createWasmRecoilMethod;
32
-
33
- var createRecoilSelector = function createRecoilSelector(keyPrefix, QueryClient, methodName) {
34
- // const propertyNames = getMessageProperties(queryMsg)
35
- // .map(method => Object.keys(method.properties)?.[0])
36
- // .filter(Boolean);
37
- // const methods = getMessageProperties(queryMsg)
38
- // .map(schema => createWasmRecoilMethod(schema))
20
+ var createRecoilSelector = function createRecoilSelector(context, keyPrefix, QueryClient, methodName) {
39
21
  var selectorName = (0, _case.camel)("".concat(methodName, "Selector"));
40
22
  var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
41
23
  var getterKey = (0, _case.camel)("".concat(keyPrefix).concat((0, _case.pascal)(methodName)));
42
- return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [// t.identifier('params')
43
- t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsIntersectionType([t.tsTypeReference(t.identifier('QueryClientParams')), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))]))))])])])))]));
24
+ return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsIntersectionType([t.tsTypeReference(t.identifier('QueryClientParams')), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))]))))])])])))]));
44
25
  };
45
26
 
46
27
  exports.createRecoilSelector = createRecoilSelector;
47
28
 
48
- var createRecoilSelectors = function createRecoilSelectors(keyPrefix, QueryClient, queryMsg) {
29
+ var createRecoilSelectors = function createRecoilSelectors(context, keyPrefix, QueryClient, queryMsg) {
49
30
  return (0, _utils.getMessageProperties)(queryMsg).map(function (schema) {
50
31
  var underscoreName = Object.keys(schema.properties)[0];
51
32
  var methodName = (0, _case.camel)(underscoreName);
52
- return createRecoilSelector(keyPrefix, QueryClient, methodName);
33
+ return createRecoilSelector(context, keyPrefix, QueryClient, methodName);
53
34
  });
54
35
  };
55
36
 
@@ -84,7 +65,7 @@ var createRecoilQueryClientType = function createRecoilQueryClientType() {
84
65
 
85
66
  exports.createRecoilQueryClientType = createRecoilQueryClientType;
86
67
 
87
- var createRecoilQueryClient = function createRecoilQueryClient(keyPrefix, QueryClient) {
68
+ var createRecoilQueryClient = function createRecoilQueryClient(context, keyPrefix, QueryClient) {
88
69
  var getterKey = (0, _case.camel)("".concat(keyPrefix, 'QueryClient'));
89
70
  return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.identifier('cosmWasmClient')]))]), t.returnStatement(t.newExpression(t.identifier(QueryClient), [t.identifier('client'), t.identifier('contractAddress')]))]), false)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(QueryClient)), t.tsTypeReference(t.identifier('QueryClientParams'))])))]));
90
71
  };
@@ -4,32 +4,27 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
 
5
5
  var _typeof = require("@babel/runtime/helpers/typeof");
6
6
 
7
- var _generator = _interopRequireDefault(require("@babel/generator"));
8
-
9
7
  var t = _interopRequireWildcard(require("@babel/types"));
10
8
 
11
- var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/basic/query_msg.json"));
9
+ var _query_msg = _interopRequireDefault(require("../../../../__fixtures__/basic/query_msg.json"));
12
10
 
13
11
  var _recoil = require("./recoil");
14
12
 
15
- 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
+ var _context = require("../context");
16
14
 
17
- 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
+ var _testUtils = require("../../test-utils");
18
16
 
19
- var expectCode = function expectCode(ast) {
20
- expect((0, _generator["default"])(ast).code).toMatchSnapshot();
21
- };
17
+ 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); }
22
18
 
23
- var printCode = function printCode(ast) {
24
- console.log((0, _generator["default"])(ast).code);
25
- };
19
+ 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; }
26
20
 
21
+ var ctx = new _context.RenderContext(_query_msg["default"]);
27
22
  it('selector', function () {
28
- expectCode((0, _recoil.createRecoilSelector)('SG721', 'SG721QueryClient', 'governanceModules'));
23
+ (0, _testUtils.expectCode)((0, _recoil.createRecoilSelector)(ctx, 'SG721', 'SG721QueryClient', 'governanceModules'));
29
24
  });
30
25
  it('selectors', function () {
31
- expectCode(t.program((0, _recoil.createRecoilSelectors)('SG721', 'SG721QueryClient', _query_msg["default"])));
26
+ (0, _testUtils.expectCode)(t.program((0, _recoil.createRecoilSelectors)(ctx, 'SG721', 'SG721QueryClient', _query_msg["default"])));
32
27
  });
33
28
  it('client', function () {
34
- expectCode((0, _recoil.createRecoilQueryClient)('SG721', 'SG721QueryClient'));
29
+ (0, _testUtils.expectCode)((0, _recoil.createRecoilQueryClient)(ctx, 'SG721', 'SG721QueryClient'));
35
30
  });
@@ -10,28 +10,20 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
 
11
11
  var _babel = require("./babel");
12
12
 
13
- var _generator = _interopRequireDefault(require("@babel/generator"));
14
-
15
13
  var t = _interopRequireWildcard(require("@babel/types"));
16
14
 
15
+ var _testUtils = require("../../test-utils");
16
+
17
17
  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); }
18
18
 
19
19
  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; }
20
20
 
21
- var expectCode = function expectCode(ast) {
22
- expect((0, _generator["default"])(ast).code).toMatchSnapshot();
23
- };
24
-
25
- var printCode = function printCode(ast) {
26
- console.log((0, _generator["default"])(ast).code);
27
- };
28
-
29
21
  it('top import', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
30
22
  return _regenerator["default"].wrap(function _callee$(_context) {
31
23
  while (1) {
32
24
  switch (_context.prev = _context.next) {
33
25
  case 0:
34
- expectCode((0, _babel.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));
26
+ (0, _testUtils.expectCode)((0, _babel.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));
35
27
 
36
28
  case 1:
37
29
  case "end":
@@ -45,7 +37,7 @@ it('interfaces', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_
45
37
  while (1) {
46
38
  switch (_context2.prev = _context2.next) {
47
39
  case 0:
48
- expectCode(t.program([t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721ReadOnlyInstance'), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // methods
40
+ (0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721ReadOnlyInstance'), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // methods
49
41
  t.tSPropertySignature(t.identifier('tokens'), t.tsTypeAnnotation(t.tsFunctionType(null, [(0, _babel.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('startAfter', t.tsTypeAnnotation(t.tsStringKeyword()), true), (0, _babel.typedIdentifier)('limit', t.tsTypeAnnotation(t.tsStringKeyword()), true)], (0, _babel.promiseTypeAnnotation)('TokensResponse'))))]))), // extends
50
42
  t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721Instance'), null, [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))], t.tSInterfaceBody([// contract address
51
43
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // METHOD
@@ -63,7 +55,7 @@ it('readonly classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
63
55
  while (1) {
64
56
  switch (_context3.prev = _context3.next) {
65
57
  case 0:
66
- expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721QueryClient', [// client
58
+ (0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721QueryClient', [// client
67
59
  (0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
68
60
  (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
69
61
  t.classMethod('constructor', t.identifier('constructor'), [(0, _babel.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), (0, _babel.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// client/contract set
@@ -86,7 +78,7 @@ it('mutation classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
86
78
  while (1) {
87
79
  switch (_context4.prev = _context4.next) {
88
80
  case 0:
89
- expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721Client', [// client
81
+ (0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721Client', [// client
90
82
  (0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // contractAddress
91
83
  (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
92
84
  t.classMethod('constructor', t.identifier('constructor'), [(0, _babel.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), (0, _babel.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// super()
@@ -107,6 +99,6 @@ it('mutation classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
107
99
  it('object parms', function () {
108
100
  var obj = t.objectPattern([t.objectProperty(t.identifier('includeExpired'), t.identifier('includeExpired'), false, true), t.objectProperty(t.identifier('tokenId'), t.identifier('tokenId'), false, true)]);
109
101
  obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([t.tsPropertySignature(t.identifier('includeExpired'), t.tsTypeAnnotation(t.tsBooleanKeyword())), t.tsPropertySignature(t.identifier('tokenId'), t.tsTypeAnnotation(t.tsStringKeyword()))]));
110
- expectCode(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _babel.arrowFunctionExpression)([obj], t.blockStatement([// body
102
+ (0, _testUtils.expectCode)(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _babel.arrowFunctionExpression)([obj], t.blockStatement([// body
111
103
  ], []), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('OwnerOfResponse'))]))))))]));
112
104
  });
@@ -15,4 +15,17 @@ Object.keys(_babel).forEach(function (key) {
15
15
  return _babel[key];
16
16
  }
17
17
  });
18
+ });
19
+
20
+ var _types = require("./types");
21
+
22
+ Object.keys(_types).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _types[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _types[key];
29
+ }
30
+ });
18
31
  });
@@ -26,31 +26,15 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
26
26
  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; }
27
27
 
28
28
  var getTypeStrFromRef = function getTypeStrFromRef($ref) {
29
- switch ($ref) {
30
- case '#/definitions/Binary':
31
- return 'Binary';
32
-
33
- default:
34
- if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
35
- return $ref.replace('#/definitions/', '');
36
- }
37
-
38
- throw new Error('what is $ref: ' + $ref);
29
+ if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
30
+ return $ref.replace('#/definitions/', '');
39
31
  }
32
+
33
+ throw new Error('what is $ref: ' + $ref);
40
34
  };
41
35
 
42
36
  var getTypeFromRef = function getTypeFromRef($ref) {
43
- switch ($ref) {
44
- case '#/definitions/Binary':
45
- return t.tsTypeReference(t.identifier('Binary'));
46
-
47
- default:
48
- if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
49
- return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
50
- }
51
-
52
- throw new Error('what is $ref: ' + $ref);
53
- }
37
+ return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
54
38
  };
55
39
 
56
40
  exports.getTypeFromRef = getTypeFromRef;
@@ -89,7 +73,7 @@ var getType = function getType(type) {
89
73
 
90
74
  exports.getType = getType;
91
75
 
92
- var getPropertyType = function getPropertyType(schema, prop) {
76
+ var getPropertyType = function getPropertyType(context, schema, prop) {
93
77
  var _schema$properties, _schema$required, _schema$required2;
94
78
 
95
79
  var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
@@ -187,12 +171,12 @@ var getPropertyType = function getPropertyType(schema, prop) {
187
171
 
188
172
  exports.getPropertyType = getPropertyType;
189
173
 
190
- function getPropertySignatureFromProp(jsonschema, prop, camelize) {
174
+ function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
191
175
  if (jsonschema.properties[prop].type === 'object') {
192
176
  if (jsonschema.properties[prop].title) {
193
177
  return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
194
178
  } else {
195
- throw new Error('createTypedObjectParams() contact maintainer');
179
+ throw new Error('getPropertySignatureFromProp() contact maintainer');
196
180
  }
197
181
  }
198
182
 
@@ -237,45 +221,63 @@ function getPropertySignatureFromProp(jsonschema, prop, camelize) {
237
221
  }
238
222
 
239
223
  try {
240
- getPropertyType(jsonschema, prop);
224
+ getPropertyType(context, jsonschema, prop);
241
225
  } catch (e) {
242
226
  console.log(e);
243
227
  console.log(jsonschema, prop);
244
228
  }
245
229
 
246
- var _getPropertyType = getPropertyType(jsonschema, prop),
230
+ var _getPropertyType = getPropertyType(context, jsonschema, prop),
247
231
  type = _getPropertyType.type,
248
232
  optional = _getPropertyType.optional;
249
233
 
250
234
  return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
251
235
  }
252
236
 
253
- var getParamsTypeAnnotation = function getParamsTypeAnnotation(jsonschema) {
237
+ var getParamsTypeAnnotation = function getParamsTypeAnnotation(context, jsonschema) {
254
238
  var _jsonschema$propertie;
255
239
 
256
- var camelize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
240
+ var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
257
241
  var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
242
+
243
+ if (!keys.length && jsonschema.$ref) {
244
+ return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
245
+ }
246
+
258
247
  if (!keys.length) return undefined;
259
248
  var typedParams = keys.map(function (prop) {
260
- return getPropertySignatureFromProp(jsonschema, prop, camelize);
249
+ return getPropertySignatureFromProp(context, jsonschema, prop, camelize);
261
250
  });
262
251
  return t.tsTypeAnnotation(t.tsTypeLiteral((0, _toConsumableArray2["default"])(typedParams)));
263
252
  };
264
253
 
265
254
  exports.getParamsTypeAnnotation = getParamsTypeAnnotation;
266
255
 
267
- var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
256
+ var createTypedObjectParams = function createTypedObjectParams(context, jsonschema) {
268
257
  var _jsonschema$propertie2;
269
258
 
270
- var camelize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
259
+ var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
271
260
  var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
272
- if (!keys.length) return; // const typedParams = keys.map(prop => getPropertySignatureFromProp(jsonschema, prop, camelize));
261
+
262
+ if (!keys.length) {
263
+ // is there a ref?
264
+ if (jsonschema.$ref) {
265
+ var _obj = context.refLookup(jsonschema.$ref);
266
+
267
+ if (_obj) {
268
+ return createTypedObjectParams(context, _obj, camelize);
269
+ }
270
+ } // no results...
271
+
272
+
273
+ return;
274
+ }
273
275
 
274
276
  var params = keys.map(function (prop) {
275
277
  return t.objectProperty(camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), false, true);
276
278
  });
277
279
  var obj = t.objectPattern((0, _toConsumableArray2["default"])(params));
278
- obj.typeAnnotation = getParamsTypeAnnotation(jsonschema, camelize);
280
+ obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
279
281
  return obj;
280
282
  };
281
283
 
@@ -1,25 +1,24 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel, pascal } from 'case';
3
- import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from './utils';
4
- import { getPropertyType, getType, createTypedObjectParams } from './utils/types';
5
- import { identifier, tsTypeOperator, propertySignature } from './utils/babel';
6
- export const createWasmQueryMethod = jsonschema => {
3
+ import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '../utils';
4
+ import { getPropertyType, getType, createTypedObjectParams } from '../utils/types';
5
+ import { identifier, propertySignature } from '../utils/babel';
6
+ export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
7
+ export const FIXED_EXECUTE_PARAMS = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
8
+ export const createWasmQueryMethod = (context, jsonschema) => {
7
9
  const underscoreName = Object.keys(jsonschema.properties)[0];
8
10
  const methodName = camel(underscoreName);
9
11
  const responseType = pascal(`${methodName}Response`);
10
- const properties = jsonschema.properties[underscoreName].properties ?? {};
11
- const obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
12
- const args = Object.keys(properties).map(prop => {
13
- return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, true);
14
- });
12
+ const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
13
+ const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
15
14
  const actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
16
15
  return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [obj] : [], t.blockStatement([t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('queryContractSmart')), [t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([actionArg])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
17
16
  };
18
- export const createQueryClass = (className, implementsClassName, queryMsg) => {
17
+ export const createQueryClass = (context, className, implementsClassName, queryMsg) => {
19
18
  const propertyNames = getMessageProperties(queryMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
20
19
  const bindings = propertyNames.map(camel).map(bindMethod);
21
20
  const methods = getMessageProperties(queryMsg).map(schema => {
22
- return createWasmQueryMethod(schema);
21
+ return createWasmQueryMethod(context, schema);
23
22
  });
24
23
  return t.exportNamedDeclaration(classDeclaration(className, [// client
25
24
  classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
@@ -27,24 +26,36 @@ export const createQueryClass = (className, implementsClassName, queryMsg) => {
27
26
  t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// client/contract set
28
27
  t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]));
29
28
  };
30
- export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
31
- export const createWasmExecMethod = jsonschema => {
32
- const underscoreName = Object.keys(jsonschema.properties)[0];
33
- const methodName = camel(underscoreName);
34
- const properties = jsonschema.properties[underscoreName].properties ?? {};
35
- const obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
36
- const args = Object.keys(properties).map(prop => {
29
+ export const getWasmMethodArgs = (context, jsonschema) => {
30
+ let keys = Object.keys(jsonschema.properties ?? {}); // only 1 degree $ref-lookup
31
+
32
+ if (!keys.length && jsonschema.$ref) {
33
+ const obj = context.refLookup(jsonschema.$ref);
34
+
35
+ if (obj) {
36
+ keys = Object.keys(obj.properties ?? {});
37
+ }
38
+ }
39
+
40
+ const args = keys.map(prop => {
37
41
  return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
38
42
  });
43
+ return args;
44
+ };
45
+ export const createWasmExecMethod = (context, jsonschema) => {
46
+ const underscoreName = Object.keys(jsonschema.properties)[0];
47
+ const methodName = camel(underscoreName);
48
+ const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
49
+ const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
39
50
  return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [// props
40
51
  obj, ...CONSTANT_EXEC_PARAMS] : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier(underscoreName), t.objectExpression([...args]))]), t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])))]), // return type
41
52
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
42
53
  };
43
- export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
54
+ export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
44
55
  const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
45
56
  const bindings = propertyNames.map(camel).map(bindMethod);
46
57
  const methods = getMessageProperties(execMsg).map(schema => {
47
- return createWasmExecMethod(schema);
58
+ return createWasmExecMethod(context, schema);
48
59
  });
49
60
  const blockStmt = [];
50
61
 
@@ -61,19 +72,19 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
61
72
  classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
62
73
  t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement(blockStmt)), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], extendsClassName ? t.identifier(extendsClassName) : null));
63
74
  };
64
- export const createExecuteInterface = (className, extendsClassName, execMsg) => {
75
+ export const createExecuteInterface = (context, className, extendsClassName, execMsg) => {
65
76
  const methods = getMessageProperties(execMsg).map(jsonschema => {
66
77
  const underscoreName = Object.keys(jsonschema.properties)[0];
67
78
  const methodName = camel(underscoreName);
68
- return createPropertyFunctionWithObjectParamsForExec(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
79
+ return createPropertyFunctionWithObjectParamsForExec(context, methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
69
80
  });
70
81
  const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
71
82
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
72
83
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
73
84
  t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
74
85
  };
75
- export const createPropertyFunctionWithObjectParams = (methodName, responseType, jsonschema) => {
76
- const obj = createTypedObjectParams(jsonschema);
86
+ export const createPropertyFunctionWithObjectParams = (context, methodName, responseType, jsonschema) => {
87
+ const obj = createTypedObjectParams(context, jsonschema);
77
88
  const func = {
78
89
  type: 'TSFunctionType',
79
90
  typeAnnotation: promiseTypeAnnotation(responseType),
@@ -81,9 +92,8 @@ export const createPropertyFunctionWithObjectParams = (methodName, responseType,
81
92
  };
82
93
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
83
94
  };
84
- export const FIXED_EXECUTE_PARAMS = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
85
- export const createPropertyFunctionWithObjectParamsForExec = (methodName, responseType, jsonschema) => {
86
- const obj = createTypedObjectParams(jsonschema);
95
+ export const createPropertyFunctionWithObjectParamsForExec = (context, methodName, responseType, jsonschema) => {
96
+ const obj = createTypedObjectParams(context, jsonschema);
87
97
  const func = {
88
98
  type: 'TSFunctionType',
89
99
  typeAnnotation: promiseTypeAnnotation(responseType),
@@ -91,16 +101,16 @@ export const createPropertyFunctionWithObjectParamsForExec = (methodName, respon
91
101
  };
92
102
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
93
103
  };
94
- export const createQueryInterface = (className, queryMsg) => {
104
+ export const createQueryInterface = (context, className, queryMsg) => {
95
105
  const methods = getMessageProperties(queryMsg).map(jsonschema => {
96
106
  const underscoreName = Object.keys(jsonschema.properties)[0];
97
107
  const methodName = camel(underscoreName);
98
108
  const responseType = pascal(`${methodName}Response`);
99
- return createPropertyFunctionWithObjectParams(methodName, responseType, jsonschema.properties[underscoreName]);
109
+ return createPropertyFunctionWithObjectParams(context, methodName, responseType, jsonschema.properties[underscoreName]);
100
110
  });
101
111
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
102
112
  };
103
- export const createTypeOrInterface = (Type, jsonschema) => {
113
+ export const createTypeOrInterface = (context, Type, jsonschema) => {
104
114
  if (jsonschema.type !== 'object') {
105
115
  if (!jsonschema.type) {
106
116
  return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
@@ -113,12 +123,12 @@ export const createTypeOrInterface = (Type, jsonschema) => {
113
123
  const {
114
124
  type,
115
125
  optional
116
- } = getPropertyType(jsonschema, prop);
126
+ } = getPropertyType(context, jsonschema, prop);
117
127
  return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
118
128
  });
119
129
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody([...props])));
120
130
  };
121
- export const createTypeInterface = jsonschema => {
131
+ export const createTypeInterface = (context, jsonschema) => {
122
132
  const Type = jsonschema.title;
123
- return createTypeOrInterface(Type, jsonschema);
133
+ return createTypeOrInterface(context, Type, jsonschema);
124
134
  };
@@ -0,0 +1 @@
1
+ export * from './client';
@@ -0,0 +1,17 @@
1
+ import message from '../../../../../__fixtures__/misc/schema/arrays.json';
2
+ import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
3
+ import { RenderContext } from '../../context';
4
+ import { expectCode } from '../../../test-utils';
5
+ const ctx = new RenderContext(message);
6
+ it('execute_msg_for__empty', () => {
7
+ expectCode(createTypeInterface(ctx, message));
8
+ });
9
+ it('query classes', () => {
10
+ expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
11
+ });
12
+ it('execute classes array types', () => {
13
+ expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, message));
14
+ });
15
+ it('execute interfaces no extends', () => {
16
+ expectCode(createExecuteInterface(ctx, 'SG721Instance', null, message));
17
+ });
@@ -0,0 +1,17 @@
1
+ import execute_msg from '../../../../../__fixtures__/daodao/cw-named-groups/execute_msg.json';
2
+ import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
3
+ import { RenderContext } from '../../context';
4
+ import { expectCode } from '../../../test-utils';
5
+ const ctx = new RenderContext(execute_msg);
6
+ it('execute_msg', () => {
7
+ expectCode(createTypeInterface(ctx, execute_msg));
8
+ });
9
+ it('query classes', () => {
10
+ expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg));
11
+ });
12
+ it('execute classes array types', () => {
13
+ expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
14
+ });
15
+ it('execute interfaces no extends', () => {
16
+ expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
17
+ });
@@ -0,0 +1,21 @@
1
+ import execute_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/execute_msg.json';
2
+ import query_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/query_msg.json';
3
+ import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
4
+ import { RenderContext } from '../../context';
5
+ import { expectCode } from '../../../test-utils';
6
+ it('execute_msg_for', () => {
7
+ const ctx = new RenderContext(execute_msg);
8
+ expectCode(createTypeInterface(ctx, execute_msg));
9
+ });
10
+ it('query classes', () => {
11
+ const ctx = new RenderContext(query_msg);
12
+ expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
13
+ });
14
+ it('execute classes array types', () => {
15
+ const ctx = new RenderContext(execute_msg);
16
+ expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
17
+ });
18
+ it('execute interfaces no extends', () => {
19
+ const ctx = new RenderContext(execute_msg);
20
+ expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
21
+ });
@@ -0,0 +1,11 @@
1
+ import query_msg from '../../../../../__fixtures__/daodao/cw-admin-factory/query_msg.json';
2
+ import { createQueryClass, createQueryInterface } from '../client';
3
+ import { RenderContext } from '../../context';
4
+ import { expectCode } from '../../../test-utils';
5
+ const ctx = new RenderContext(query_msg);
6
+ it('query classes', () => {
7
+ expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
8
+ });
9
+ it('query interface', () => {
10
+ expectCode(createQueryInterface(ctx, 'ReadOnlyInstance', query_msg));
11
+ });
@@ -0,0 +1,17 @@
1
+ import execute_msg_for__empty from '../../../../../__fixtures__/sg721/execute_msg_for__empty.json';
2
+ import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
3
+ import { RenderContext } from '../../context';
4
+ import { expectCode } from '../../../test-utils';
5
+ const ctx = new RenderContext(execute_msg_for__empty);
6
+ it('execute_msg_for__empty', () => {
7
+ expectCode(createTypeInterface(ctx, execute_msg_for__empty));
8
+ });
9
+ it('query classes', () => {
10
+ expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg_for__empty));
11
+ });
12
+ it('execute classes array types', () => {
13
+ expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_for__empty));
14
+ });
15
+ it('execute interfaces no extends', () => {
16
+ expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg_for__empty));
17
+ });