wasm-ast-types 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main/messages.js CHANGED
@@ -11,152 +11,21 @@ exports.createFromPartialInterface = exports.createFromPartialClass = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
14
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
-
16
14
  var t = _interopRequireWildcard(require("@babel/types"));
17
15
 
18
16
  var _case = require("case");
19
17
 
20
18
  var _utils = require("./utils");
21
19
 
22
- 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); }
23
-
24
- 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; }
25
-
26
- var getTypeFromRef = function getTypeFromRef($ref) {
27
- switch ($ref) {
28
- case '#/definitions/Binary':
29
- return t.tsTypeReference(t.identifier('Binary'));
30
-
31
- default:
32
- if ($ref.startsWith('#/definitions/')) {
33
- return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
34
- }
35
-
36
- throw new Error('what is $ref: ' + $ref);
37
- }
38
- };
39
-
40
- var getArrayTypeFromRef = function getArrayTypeFromRef($ref) {
41
- return t.tsArrayType(getTypeFromRef($ref));
42
- };
43
-
44
- var getArrayTypeFromType = function getArrayTypeFromType(type) {
45
- return t.tsArrayType(getType(type));
46
- }; // MARKED AS NOT DRY
47
-
48
-
49
- var identifier = function identifier(name, typeAnnotation) {
50
- var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
51
- var type = t.identifier(name);
52
- type.typeAnnotation = typeAnnotation;
53
- type.optional = optional;
54
- return type;
55
- };
56
-
57
- var getType = function getType(type) {
58
- switch (type) {
59
- case 'string':
60
- return t.tsStringKeyword();
61
-
62
- case 'boolean':
63
- return t.tSBooleanKeyword();
64
-
65
- case 'integer':
66
- return t.tsNumberKeyword();
67
-
68
- default:
69
- throw new Error('what is type: ' + type);
70
- }
71
- }; // MARKED AS NOT DRY
72
-
73
-
74
- var getPropertyType = function getPropertyType(schema, prop) {
75
- var _schema$properties, _schema$required, _schema$required2;
76
-
77
- var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
78
- var info = props[prop];
79
- var type = null;
80
- var optional = (_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(prop);
20
+ var _types2 = require("./utils/types");
81
21
 
82
- if (info.allOf && info.allOf.length === 1) {
83
- info = info.allOf[0];
84
- }
22
+ var _babel = require("./utils/babel");
85
23
 
86
- if (typeof info.$ref === 'string') {
87
- type = getTypeFromRef(info.$ref);
88
- }
89
-
90
- if (Array.isArray(info.anyOf)) {
91
- // assuming 2nd is null, but let's check to ensure
92
- if (info.anyOf.length !== 2) {
93
- throw new Error('case not handled by transpiler. contact maintainers.');
94
- }
95
-
96
- var _info$anyOf = (0, _slicedToArray2["default"])(info.anyOf, 2),
97
- nullableType = _info$anyOf[0],
98
- nullType = _info$anyOf[1];
99
-
100
- if ((nullType === null || nullType === void 0 ? void 0 : nullType.type) !== 'null') {
101
- throw new Error('case not handled by transpiler. contact maintainers.');
102
- }
103
-
104
- type = getTypeFromRef(nullableType === null || nullableType === void 0 ? void 0 : nullableType.$ref);
105
- optional = true;
106
- }
107
-
108
- if (typeof info.type === 'string') {
109
- if (info.type === 'array') {
110
- if (info.items.$ref) {
111
- type = getArrayTypeFromRef(info.items.$ref);
112
- } else {
113
- type = getArrayTypeFromType(info.items.type);
114
- }
115
- } else {
116
- type = getType(info.type);
117
- }
118
- }
119
-
120
- if (Array.isArray(info.type)) {
121
- // assuming 2nd is null, but let's check to ensure
122
- if (info.type.length !== 2) {
123
- throw new Error('case not handled by transpiler. contact maintainers.');
124
- }
125
-
126
- var _info$type = (0, _slicedToArray2["default"])(info.type, 2),
127
- _nullableType = _info$type[0],
128
- _nullType = _info$type[1];
129
-
130
- if (_nullType !== 'null') {
131
- throw new Error('case not handled by transpiler. contact maintainers.');
132
- }
133
-
134
- type = getType(_nullableType);
135
- optional = true;
136
- }
137
-
138
- if (!type) {
139
- throw new Error('cannot find type for ' + JSON.stringify(info));
140
- }
141
-
142
- if ((_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(prop)) {
143
- optional = false;
144
- }
145
-
146
- return {
147
- type: type,
148
- optional: optional
149
- };
150
- };
151
-
152
- var tsTypeOperator = function tsTypeOperator(typeAnnotation, operator) {
153
- var obj = t.tsTypeOperator(typeAnnotation);
154
- obj.operator = operator;
155
- return obj;
156
- }; // MARKED AS NOT DRY
24
+ 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); }
157
25
 
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; }
158
27
 
159
- var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
28
+ var createWasmExecMethodPartial = function createWasmExecMethodPartial(jsonschema) {
160
29
  var _jsonschema$propertie;
161
30
 
162
31
  var underscoreName = Object.keys(jsonschema.properties)[0];
@@ -189,7 +58,7 @@ var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
189
58
  // identifier('memo', t.tsTypeAnnotation(
190
59
  // t.tsStringKeyword()
191
60
  // ), true),
192
- identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
61
+ (0, _babel.identifier)('funds', t.tsTypeAnnotation((0, _babel.tsTypeOperator)(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
193
62
  return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(obj ? [// props
194
63
  obj].concat(constantParams) : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), t.objectExpression(args))])])])), t.objectProperty(t.identifier('funds'), t.identifier('funds'), false, true)])]))]))]), // return type
195
64
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
@@ -203,7 +72,7 @@ var createFromPartialClass = function createFromPartialClass(className, implemen
203
72
  }).filter(Boolean);
204
73
  var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
205
74
  var methods = (0, _utils.getMessageProperties)(execMsg).map(function (schema) {
206
- return createWasmExecMethod(schema);
75
+ return createWasmExecMethodPartial(schema);
207
76
  });
208
77
  var blockStmt = [];
209
78
  [].push.apply(blockStmt, [t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress')))].concat((0, _toConsumableArray2["default"])(bindings)));
@@ -230,25 +99,6 @@ var createFromPartialInterface = function createFromPartialInterface(className,
230
99
 
231
100
  exports.createFromPartialInterface = createFromPartialInterface;
232
101
 
233
- var propertySignature = function propertySignature(name, typeAnnotation) {
234
- var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
235
- // prop.leadingComments = [{
236
- // type: 'Comment',
237
- // value: ' Data on the token itself'
238
- // }];
239
- // prop.leadingComments = [{
240
- // type: 'CommentBlock',
241
- // value: '* Data on the token itself'
242
- // }];
243
- return {
244
- type: 'TSPropertySignature',
245
- key: t.identifier(name),
246
- typeAnnotation: typeAnnotation,
247
- optional: optional
248
- };
249
- }; // MARKED AS NOT DRY
250
-
251
-
252
102
  var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
253
103
  var _jsonschema$propertie2;
254
104
 
@@ -256,11 +106,11 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
256
106
  var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
257
107
  if (!keys.length) return;
258
108
  var typedParams = keys.map(function (prop) {
259
- var _getPropertyType = getPropertyType(jsonschema, prop),
109
+ var _getPropertyType = (0, _types2.getPropertyType)(jsonschema, prop),
260
110
  type = _getPropertyType.type,
261
111
  optional = _getPropertyType.optional;
262
112
 
263
- return propertySignature(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
113
+ return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
264
114
  });
265
115
  var params = keys.map(function (prop) {
266
116
  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);
@@ -288,7 +138,7 @@ var createPropertyFunctionWithObjectParamsForPartial = function createPropertyFu
288
138
  // identifier('memo', t.tsTypeAnnotation(
289
139
  // t.tsStringKeyword()
290
140
  // ), true),
291
- identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
141
+ (0, _babel.identifier)('funds', t.tsTypeAnnotation((0, _babel.tsTypeOperator)(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
292
142
  var func = {
293
143
  type: 'TSFunctionType',
294
144
  typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
 
5
5
  var _generator = _interopRequireDefault(require("@babel/generator"));
6
6
 
7
- var _execute_msg_for__empty = _interopRequireDefault(require("./__fixtures__/schema/execute_msg_for__empty.json"));
7
+ var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/basic/execute_msg_for__empty.json"));
8
8
 
9
9
  var _messages = require("./messages");
10
10
 
@@ -17,7 +17,9 @@ var _case = require("case");
17
17
 
18
18
  var _utils = require("./utils");
19
19
 
20
- var _wasm = require("./wasm");
20
+ var _babel = require("./utils/babel");
21
+
22
+ var _types2 = require("./utils/types");
21
23
 
22
24
  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); }
23
25
 
@@ -104,10 +106,10 @@ var getProps = function getProps(jsonschema, camelize) {
104
106
  var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
105
107
  if (!keys.length) return [];
106
108
  return keys.map(function (prop) {
107
- var _getPropertyType = (0, _wasm.getPropertyType)(jsonschema, prop),
109
+ var _getPropertyType = (0, _types2.getPropertyType)(jsonschema, prop),
108
110
  type = _getPropertyType.type,
109
111
  optional = _getPropertyType.optional;
110
112
 
111
- return (0, _wasm.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
113
+ return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
112
114
  });
113
115
  };
@@ -8,7 +8,7 @@ var _generator = _interopRequireDefault(require("@babel/generator"));
8
8
 
9
9
  var t = _interopRequireWildcard(require("@babel/types"));
10
10
 
11
- var _query_msg = _interopRequireDefault(require("./__fixtures__/schema/query_msg.json"));
11
+ var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/basic/query_msg.json"));
12
12
 
13
13
  var _reactQuery = require("./react-query");
14
14
 
@@ -8,7 +8,7 @@ var _generator = _interopRequireDefault(require("@babel/generator"));
8
8
 
9
9
  var t = _interopRequireWildcard(require("@babel/types"));
10
10
 
11
- var _query_msg = _interopRequireDefault(require("./__fixtures__/schema/query_msg.json"));
11
+ var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/basic/query_msg.json"));
12
12
 
13
13
  var _recoil = require("./recoil");
14
14
 
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.typedIdentifier = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.promiseTypeAnnotation = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = exports.getMessageProperties = exports.getFieldDimensionality = exports.classProperty = exports.classDeclaration = exports.callExpression = exports.bindMethod = exports.arrowFunctionExpression = exports.arrayTypeNDimensions = exports.FieldTypeAsts = void 0;
10
+ exports.typedIdentifier = exports.tsTypeOperator = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.propertySignature = exports.promiseTypeAnnotation = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = exports.identifier = exports.getMessageProperties = exports.getFieldDimensionality = exports.classProperty = exports.classDeclaration = exports.callExpression = exports.bindMethod = exports.arrowFunctionExpression = exports.arrayTypeNDimensions = exports.FieldTypeAsts = void 0;
11
11
 
12
12
  var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
13
13
 
@@ -21,6 +21,36 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
21
21
 
22
22
  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; }
23
23
 
24
+ var propertySignature = function propertySignature(name, typeAnnotation) {
25
+ var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
26
+ return {
27
+ type: 'TSPropertySignature',
28
+ key: t.identifier(name),
29
+ typeAnnotation: typeAnnotation,
30
+ optional: optional
31
+ };
32
+ };
33
+
34
+ exports.propertySignature = propertySignature;
35
+
36
+ var identifier = function identifier(name, typeAnnotation) {
37
+ var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
38
+ var type = t.identifier(name);
39
+ type.typeAnnotation = typeAnnotation;
40
+ type.optional = optional;
41
+ return type;
42
+ };
43
+
44
+ exports.identifier = identifier;
45
+
46
+ var tsTypeOperator = function tsTypeOperator(typeAnnotation, operator) {
47
+ var obj = t.tsTypeOperator(typeAnnotation);
48
+ obj.operator = operator;
49
+ return obj;
50
+ };
51
+
52
+ exports.tsTypeOperator = tsTypeOperator;
53
+
24
54
  var getMessageProperties = function getMessageProperties(msg) {
25
55
  if (msg.anyOf) return msg.anyOf;
26
56
  if (msg.oneOf) return msg.oneOf;
@@ -8,7 +8,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
8
8
 
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
 
11
- var _utils = require("./utils");
11
+ var _babel = require("./babel");
12
12
 
13
13
  var _generator = _interopRequireDefault(require("@babel/generator"));
14
14
 
@@ -31,7 +31,7 @@ it('top import', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_
31
31
  while (1) {
32
32
  switch (_context.prev = _context.next) {
33
33
  case 0:
34
- expectCode((0, _utils.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));
34
+ expectCode((0, _babel.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));
35
35
 
36
36
  case 1:
37
37
  case "end":
@@ -46,10 +46,10 @@ it('interfaces', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_
46
46
  switch (_context2.prev = _context2.next) {
47
47
  case 0:
48
48
  expectCode(t.program([t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721ReadOnlyInstance'), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // methods
49
- t.tSPropertySignature(t.identifier('tokens'), t.tsTypeAnnotation(t.tsFunctionType(null, [(0, _utils.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('startAfter', t.tsTypeAnnotation(t.tsStringKeyword()), true), (0, _utils.typedIdentifier)('limit', t.tsTypeAnnotation(t.tsStringKeyword()), true)], (0, _utils.promiseTypeAnnotation)('TokensResponse'))))]))), // extends
49
+ 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
50
  t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721Instance'), null, [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))], t.tSInterfaceBody([// contract address
51
51
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // METHOD
52
- t.tSPropertySignature(t.identifier('mint'), t.tsTypeAnnotation(t.tsFunctionType(null, [(0, _utils.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('anotherProp', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('prop3', t.tsTypeAnnotation(t.tsStringKeyword()))], (0, _utils.promiseTypeAnnotation)('ExecuteResult'))))])))]));
52
+ t.tSPropertySignature(t.identifier('mint'), t.tsTypeAnnotation(t.tsFunctionType(null, [(0, _babel.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('anotherProp', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('prop3', t.tsTypeAnnotation(t.tsStringKeyword()))], (0, _babel.promiseTypeAnnotation)('ExecuteResult'))))])))]));
53
53
 
54
54
  case 1:
55
55
  case "end":
@@ -63,15 +63,15 @@ it('readonly classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
63
63
  while (1) {
64
64
  switch (_context3.prev = _context3.next) {
65
65
  case 0:
66
- expectCode(t.program([t.exportNamedDeclaration((0, _utils.classDeclaration)('SG721QueryClient', [// client
67
- (0, _utils.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
68
- (0, _utils.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
69
- t.classMethod('constructor', t.identifier('constructor'), [(0, _utils.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), (0, _utils.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// client/contract set
66
+ expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721QueryClient', [// client
67
+ (0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
68
+ (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
69
+ 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
70
70
  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
71
- (0, _utils.bindMethod)('approval'), (0, _utils.bindMethod)('otherProp'), (0, _utils.bindMethod)('hello'), (0, _utils.bindMethod)('mintme')])), // methods:
72
- t.classProperty(t.identifier('approval'), (0, _utils.arrowFunctionExpression)([// props
73
- (0, _utils.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), //
74
- (0, _utils.typedIdentifier)('spender', t.tsTypeAnnotation(t.tsStringKeyword()))], 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([// props
71
+ (0, _babel.bindMethod)('approval'), (0, _babel.bindMethod)('otherProp'), (0, _babel.bindMethod)('hello'), (0, _babel.bindMethod)('mintme')])), // methods:
72
+ t.classProperty(t.identifier('approval'), (0, _babel.arrowFunctionExpression)([// props
73
+ (0, _babel.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), //
74
+ (0, _babel.typedIdentifier)('spender', t.tsTypeAnnotation(t.tsStringKeyword()))], 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([// props
75
75
  t.objectProperty(t.identifier('owner'), t.identifier('owner'), false, true), t.objectProperty(t.identifier('spender'), t.identifier('spender'), false, true)])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ApprovalResponse'))]))), true))], [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))]))]));
76
76
 
77
77
  case 1:
@@ -86,15 +86,15 @@ it('mutation classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
86
86
  while (1) {
87
87
  switch (_context4.prev = _context4.next) {
88
88
  case 0:
89
- expectCode(t.program([t.exportNamedDeclaration((0, _utils.classDeclaration)('SG721Client', [// client
90
- (0, _utils.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // contractAddress
91
- (0, _utils.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
92
- t.classMethod('constructor', t.identifier('constructor'), [(0, _utils.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), (0, _utils.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// super()
89
+ expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721Client', [// client
90
+ (0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // contractAddress
91
+ (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
92
+ 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()
93
93
  t.expressionStatement(t.callExpression(t["super"](), [t.identifier('client'), t.identifier('contractAddress')])), // client/contract set
94
94
  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
95
- (0, _utils.bindMethod)('approval'), (0, _utils.bindMethod)('otherProp'), (0, _utils.bindMethod)('hello'), (0, _utils.bindMethod)('mintme')])), // methods:
96
- t.classProperty(t.identifier('mint'), (0, _utils.arrowFunctionExpression)([// props
97
- (0, _utils.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('tokenId', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('token_uri', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier('mint'), t.objectExpression([t.objectProperty(t.identifier('token_id'), t.identifier('tokenId')), t.objectProperty(t.identifier('owner'), t.identifier('owner')), t.objectProperty(t.identifier('token_uri'), t.identifier('token_uri')), t.objectProperty(t.identifier('expression'), t.objectExpression([]))]))]), t.stringLiteral('auto')])))]), // return type
95
+ (0, _babel.bindMethod)('approval'), (0, _babel.bindMethod)('otherProp'), (0, _babel.bindMethod)('hello'), (0, _babel.bindMethod)('mintme')])), // methods:
96
+ t.classProperty(t.identifier('mint'), (0, _babel.arrowFunctionExpression)([// props
97
+ (0, _babel.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('tokenId', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('token_uri', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier('mint'), t.objectExpression([t.objectProperty(t.identifier('token_id'), t.identifier('tokenId')), t.objectProperty(t.identifier('owner'), t.identifier('owner')), t.objectProperty(t.identifier('token_uri'), t.identifier('token_uri')), t.objectProperty(t.identifier('expression'), t.objectExpression([]))]))]), t.stringLiteral('auto')])))]), // return type
98
98
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true))], [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))], t.identifier('SG721QueryClient')))]));
99
99
 
100
100
  case 1:
@@ -107,6 +107,6 @@ it('mutation classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
107
107
  it('object parms', function () {
108
108
  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
109
  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, _utils.arrowFunctionExpression)([obj], t.blockStatement([// body
110
+ expectCode(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _babel.arrowFunctionExpression)([obj], t.blockStatement([// body
111
111
  ], []), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('OwnerOfResponse'))]))))))]));
112
112
  });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _babel = require("./babel");
8
+
9
+ Object.keys(_babel).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _babel[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _babel[key];
16
+ }
17
+ });
18
+ });
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.getType = exports.getPropertyType = void 0;
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var t = _interopRequireWildcard(require("@babel/types"));
15
+
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
+
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
+
20
+ var getTypeFromRef = function getTypeFromRef($ref) {
21
+ switch ($ref) {
22
+ case '#/definitions/Binary':
23
+ return t.tsTypeReference(t.identifier('Binary'));
24
+
25
+ default:
26
+ if ($ref.startsWith('#/definitions/')) {
27
+ return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
28
+ }
29
+
30
+ throw new Error('what is $ref: ' + $ref);
31
+ }
32
+ };
33
+
34
+ var getArrayTypeFromRef = function getArrayTypeFromRef($ref) {
35
+ return t.tsArrayType(getTypeFromRef($ref));
36
+ };
37
+
38
+ var getArrayTypeFromType = function getArrayTypeFromType(type) {
39
+ return t.tsArrayType(getType(type));
40
+ };
41
+
42
+ var getType = function getType(type) {
43
+ switch (type) {
44
+ case 'string':
45
+ return t.tsStringKeyword();
46
+
47
+ case 'boolean':
48
+ return t.tSBooleanKeyword();
49
+
50
+ case 'integer':
51
+ return t.tsNumberKeyword();
52
+
53
+ default:
54
+ throw new Error('contact maintainers [unknown type]: ' + type);
55
+ }
56
+ };
57
+
58
+ exports.getType = getType;
59
+
60
+ var getPropertyType = function getPropertyType(schema, prop) {
61
+ var _schema$properties, _schema$required, _schema$required2;
62
+
63
+ var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
64
+ var info = props[prop];
65
+ var type = null;
66
+ var optional = (_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(prop);
67
+
68
+ if (info.allOf && info.allOf.length === 1) {
69
+ info = info.allOf[0];
70
+ }
71
+
72
+ if (typeof info.$ref === 'string') {
73
+ type = getTypeFromRef(info.$ref);
74
+ }
75
+
76
+ if (Array.isArray(info.anyOf)) {
77
+ // assuming 2nd is null, but let's check to ensure
78
+ if (info.anyOf.length !== 2) {
79
+ throw new Error('case not handled by transpiler. contact maintainers.');
80
+ }
81
+
82
+ var _info$anyOf = (0, _slicedToArray2["default"])(info.anyOf, 2),
83
+ nullableType = _info$anyOf[0],
84
+ nullType = _info$anyOf[1];
85
+
86
+ if ((nullType === null || nullType === void 0 ? void 0 : nullType.type) !== 'null') {
87
+ throw new Error('case not handled by transpiler. contact maintainers.');
88
+ }
89
+
90
+ type = getTypeFromRef(nullableType === null || nullableType === void 0 ? void 0 : nullableType.$ref);
91
+ optional = true;
92
+ }
93
+
94
+ if (typeof info.type === 'string') {
95
+ if (info.type === 'array') {
96
+ if (info.items.$ref) {
97
+ type = getArrayTypeFromRef(info.items.$ref);
98
+ } else {
99
+ type = getArrayTypeFromType(info.items.type);
100
+ }
101
+ } else {
102
+ type = getType(info.type);
103
+ }
104
+ }
105
+
106
+ if (Array.isArray(info.type)) {
107
+ // assuming 2nd is null, but let's check to ensure
108
+ if (info.type.length !== 2) {
109
+ throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
110
+ }
111
+
112
+ var _info$type = (0, _slicedToArray2["default"])(info.type, 2),
113
+ _nullableType = _info$type[0],
114
+ _nullType = _info$type[1];
115
+
116
+ if (_nullType !== 'null') {
117
+ throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
118
+ }
119
+
120
+ if (_nullableType === 'array') {
121
+ type = t.tsArrayType(getType(info.items.type));
122
+ } else {
123
+ type = getType(_nullableType);
124
+ }
125
+
126
+ optional = true;
127
+ }
128
+
129
+ if (!type) {
130
+ throw new Error('cannot find type for ' + JSON.stringify(info));
131
+ }
132
+
133
+ if ((_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(prop)) {
134
+ optional = false;
135
+ }
136
+
137
+ return {
138
+ type: type,
139
+ optional: optional
140
+ };
141
+ };
142
+
143
+ exports.getPropertyType = getPropertyType;