wasm-ast-types 0.26.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +1 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
package/main/utils/index.js
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
var _exportNames = {
|
7
|
-
OPTIONAL_FUNDS_PARAM: true,
|
8
|
-
FIXED_EXECUTE_PARAMS: true,
|
9
|
-
PROVIDER_TYPES: true
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "FIXED_EXECUTE_PARAMS", {
|
12
|
-
enumerable: true,
|
13
|
-
get: function get() {
|
14
|
-
return _constants.FIXED_EXECUTE_PARAMS;
|
15
|
-
}
|
16
|
-
});
|
17
|
-
Object.defineProperty(exports, "OPTIONAL_FUNDS_PARAM", {
|
18
|
-
enumerable: true,
|
19
|
-
get: function get() {
|
20
|
-
return _constants.OPTIONAL_FUNDS_PARAM;
|
21
|
-
}
|
22
|
-
});
|
23
|
-
Object.defineProperty(exports, "PROVIDER_TYPES", {
|
24
|
-
enumerable: true,
|
25
|
-
get: function get() {
|
26
|
-
return _constants.PROVIDER_TYPES;
|
27
|
-
}
|
28
|
-
});
|
29
|
-
var _babel = require("./babel");
|
30
|
-
Object.keys(_babel).forEach(function (key) {
|
31
|
-
if (key === "default" || key === "__esModule") return;
|
32
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
33
|
-
if (key in exports && exports[key] === _babel[key]) return;
|
34
|
-
Object.defineProperty(exports, key, {
|
35
|
-
enumerable: true,
|
36
|
-
get: function get() {
|
37
|
-
return _babel[key];
|
38
|
-
}
|
39
|
-
});
|
40
|
-
});
|
41
|
-
var _types = require("./types");
|
42
|
-
Object.keys(_types).forEach(function (key) {
|
43
|
-
if (key === "default" || key === "__esModule") return;
|
44
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
45
|
-
if (key in exports && exports[key] === _types[key]) return;
|
46
|
-
Object.defineProperty(exports, key, {
|
47
|
-
enumerable: true,
|
48
|
-
get: function get() {
|
49
|
-
return _types[key];
|
50
|
-
}
|
51
|
-
});
|
52
|
-
});
|
53
|
-
var _ref = require("./ref");
|
54
|
-
Object.keys(_ref).forEach(function (key) {
|
55
|
-
if (key === "default" || key === "__esModule") return;
|
56
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
57
|
-
if (key in exports && exports[key] === _ref[key]) return;
|
58
|
-
Object.defineProperty(exports, key, {
|
59
|
-
enumerable: true,
|
60
|
-
get: function get() {
|
61
|
-
return _ref[key];
|
62
|
-
}
|
63
|
-
});
|
64
|
-
});
|
65
|
-
var _constants = require("./constants");
|
package/main/utils/ref.js
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.refLookup = void 0;
|
7
|
-
var refLookup = function refLookup($ref, schema) {
|
8
|
-
var _schema$definitions;
|
9
|
-
var refName = $ref.replace('#/definitions/', '');
|
10
|
-
return (_schema$definitions = schema.definitions) === null || _schema$definitions === void 0 ? void 0 : _schema$definitions[refName];
|
11
|
-
};
|
12
|
-
exports.refLookup = refLookup;
|
package/main/utils/types.js
DELETED
@@ -1,343 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.getParamsTypeAnnotation = exports.detectType = exports.createTypedObjectParams = void 0;
|
9
|
-
exports.getPropertySignatureFromProp = getPropertySignatureFromProp;
|
10
|
-
exports.getPropertyType = void 0;
|
11
|
-
exports.getResponseType = getResponseType;
|
12
|
-
exports.getTypeInfo = exports.getTypeFromRef = exports.getType = void 0;
|
13
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
14
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
15
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
16
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
17
|
-
var _case = require("case");
|
18
|
-
var _babel = require("./babel");
|
19
|
-
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); }
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
|
21
|
-
function getResponseType(context, underscoreName) {
|
22
|
-
var _context$contract$res, _context$contract, _context$contract$res2, _context$contract$res3;
|
23
|
-
var methodName = (0, _case.camel)(underscoreName);
|
24
|
-
return (0, _case.pascal)((_context$contract$res = (_context$contract = context.contract) === null || _context$contract === void 0 ? void 0 : (_context$contract$res2 = _context$contract.responses) === null || _context$contract$res2 === void 0 ? void 0 : (_context$contract$res3 = _context$contract$res2[underscoreName]) === null || _context$contract$res3 === void 0 ? void 0 : _context$contract$res3.title) !== null && _context$contract$res !== void 0 ? _context$contract$res : // after v1.1 is adopted, we can deprecate this and require the above response
|
25
|
-
"".concat(methodName, "Response"));
|
26
|
-
}
|
27
|
-
;
|
28
|
-
var getTypeStrFromRef = function getTypeStrFromRef($ref) {
|
29
|
-
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
|
30
|
-
return $ref.replace('#/definitions/', '');
|
31
|
-
}
|
32
|
-
throw new Error('what is $ref: ' + $ref);
|
33
|
-
};
|
34
|
-
var getTypeFromRef = function getTypeFromRef($ref) {
|
35
|
-
return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
|
36
|
-
};
|
37
|
-
exports.getTypeFromRef = getTypeFromRef;
|
38
|
-
var getArrayTypeFromRef = function getArrayTypeFromRef($ref) {
|
39
|
-
return t.tsArrayType(getTypeFromRef($ref));
|
40
|
-
};
|
41
|
-
var getTypeOrRef = function getTypeOrRef(obj) {
|
42
|
-
if (obj.type) {
|
43
|
-
return getType(obj.type);
|
44
|
-
}
|
45
|
-
if (obj.$ref) {
|
46
|
-
return getTypeFromRef(obj.$ref);
|
47
|
-
}
|
48
|
-
throw new Error('contact maintainers cannot find type for ' + obj);
|
49
|
-
};
|
50
|
-
var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
51
|
-
// passing in [{"type":"string"}]
|
52
|
-
if (Array.isArray(items)) {
|
53
|
-
var _items$;
|
54
|
-
if (((_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.type) === 'array') {
|
55
|
-
return getArrayTypeFromItems(items[0]);
|
56
|
-
}
|
57
|
-
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0])));
|
58
|
-
}
|
59
|
-
|
60
|
-
// passing in {"items": [{"type":"string"}]}
|
61
|
-
var detect = detectType(items.type);
|
62
|
-
if (detect.type === 'array') {
|
63
|
-
if (Array.isArray(items.items)) {
|
64
|
-
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items.items[0])));
|
65
|
-
} else {
|
66
|
-
return t.tsArrayType(getArrayTypeFromItems(items.items));
|
67
|
-
}
|
68
|
-
}
|
69
|
-
return t.tsArrayType(getType(detect.type));
|
70
|
-
};
|
71
|
-
var detectType = function detectType(type) {
|
72
|
-
var optional = false;
|
73
|
-
var theType = '';
|
74
|
-
if (Array.isArray(type)) {
|
75
|
-
if (type.length !== 2) {
|
76
|
-
throw new Error('[getType(array length)] case not handled by transpiler. contact maintainers.');
|
77
|
-
}
|
78
|
-
var _type = (0, _slicedToArray2["default"])(type, 2),
|
79
|
-
nullableType = _type[0],
|
80
|
-
nullType = _type[1];
|
81
|
-
if (nullType !== 'null') {
|
82
|
-
throw new Error('[getType(null)] case not handled by transpiler. contact maintainers.');
|
83
|
-
}
|
84
|
-
theType = nullableType;
|
85
|
-
optional = true;
|
86
|
-
} else {
|
87
|
-
theType = type;
|
88
|
-
}
|
89
|
-
return {
|
90
|
-
type: theType,
|
91
|
-
optional: optional
|
92
|
-
};
|
93
|
-
};
|
94
|
-
exports.detectType = detectType;
|
95
|
-
var getTypeInfo = function getTypeInfo(info) {
|
96
|
-
var type = undefined;
|
97
|
-
var optional = undefined;
|
98
|
-
if (Array.isArray(info.anyOf)) {
|
99
|
-
// assuming 2nd is null, but let's check to ensure
|
100
|
-
if (info.anyOf.length !== 2) {
|
101
|
-
throw new Error('case not handled by transpiler. contact maintainers.');
|
102
|
-
}
|
103
|
-
var _info$anyOf = (0, _slicedToArray2["default"])(info.anyOf, 2),
|
104
|
-
nullableType = _info$anyOf[0],
|
105
|
-
nullType = _info$anyOf[1];
|
106
|
-
if ((nullType === null || nullType === void 0 ? void 0 : nullType.type) !== 'null') {
|
107
|
-
throw new Error('[nullableType.type]: case not handled by transpiler. contact maintainers.');
|
108
|
-
}
|
109
|
-
if (!(nullableType !== null && nullableType !== void 0 && nullableType.$ref)) {
|
110
|
-
if (nullableType.title) {
|
111
|
-
type = t.tsTypeReference(t.identifier(nullableType.title));
|
112
|
-
} else {
|
113
|
-
throw new Error('[nullableType.title] case not handled by transpiler. contact maintainers.');
|
114
|
-
}
|
115
|
-
} else {
|
116
|
-
type = getTypeFromRef(nullableType === null || nullableType === void 0 ? void 0 : nullableType.$ref);
|
117
|
-
}
|
118
|
-
optional = true;
|
119
|
-
}
|
120
|
-
if (typeof info.type === 'string') {
|
121
|
-
if (info.type === 'array') {
|
122
|
-
if ((0, _typeof2["default"])(info.items) === 'object' && !Array.isArray(info.items)) {
|
123
|
-
if (info.items.$ref) {
|
124
|
-
type = getArrayTypeFromRef(info.items.$ref);
|
125
|
-
} else if (info.items.title) {
|
126
|
-
type = t.tsArrayType(t.tsTypeReference(t.identifier(info.items.title)));
|
127
|
-
} else if (info.items.type) {
|
128
|
-
type = getArrayTypeFromItems(info.items);
|
129
|
-
} else {
|
130
|
-
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
131
|
-
}
|
132
|
-
} else {
|
133
|
-
if (Array.isArray(info.items)) {
|
134
|
-
type = getArrayTypeFromItems(info.items);
|
135
|
-
// console.log(typeof info.items === 'object');
|
136
|
-
// console.log(Array.isArray(info.items));
|
137
|
-
// console.log(info);
|
138
|
-
} else {
|
139
|
-
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
140
|
-
}
|
141
|
-
}
|
142
|
-
} else {
|
143
|
-
var detect = detectType(info.type);
|
144
|
-
type = getType(detect.type);
|
145
|
-
optional = detect.optional;
|
146
|
-
}
|
147
|
-
}
|
148
|
-
if (Array.isArray(info.type)) {
|
149
|
-
// assuming 2nd is null, but let's check to ensure
|
150
|
-
if (info.type.length !== 2) {
|
151
|
-
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
152
|
-
}
|
153
|
-
var _info$type = (0, _slicedToArray2["default"])(info.type, 2),
|
154
|
-
_nullableType = _info$type[0],
|
155
|
-
_nullType = _info$type[1];
|
156
|
-
if (_nullType !== 'null') {
|
157
|
-
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
158
|
-
}
|
159
|
-
if (_nullableType === 'array' && (0, _typeof2["default"])(info.items) === 'object' && !Array.isArray(info.items)) {
|
160
|
-
if (info.items.type) {
|
161
|
-
var _detect = detectType(info.items.type);
|
162
|
-
if (_detect.type === 'array') {
|
163
|
-
// wen recursion?
|
164
|
-
type = t.tsArrayType(getArrayTypeFromItems(info.items));
|
165
|
-
} else {
|
166
|
-
type = t.tsArrayType(getType(_detect.type));
|
167
|
-
}
|
168
|
-
optional = _detect.optional;
|
169
|
-
} else if (info.items.$ref) {
|
170
|
-
type = getArrayTypeFromRef(info.items.$ref);
|
171
|
-
// } else if (info.items.title) {
|
172
|
-
// type = t.tsArrayType(
|
173
|
-
// t.tsTypeReference(
|
174
|
-
// t.identifier(info.items.title)
|
175
|
-
// )
|
176
|
-
// );
|
177
|
-
} else if (info.items.type) {
|
178
|
-
type = getArrayTypeFromItems(info.items);
|
179
|
-
} else {
|
180
|
-
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
181
|
-
}
|
182
|
-
} else {
|
183
|
-
var _detect2 = detectType(_nullableType);
|
184
|
-
optional = _detect2.optional;
|
185
|
-
if (_detect2.type === 'array') {
|
186
|
-
type = getArrayTypeFromItems(info.items);
|
187
|
-
} else {
|
188
|
-
type = getType(_detect2.type);
|
189
|
-
}
|
190
|
-
}
|
191
|
-
optional = true;
|
192
|
-
}
|
193
|
-
return {
|
194
|
-
type: type,
|
195
|
-
optional: optional
|
196
|
-
};
|
197
|
-
};
|
198
|
-
exports.getTypeInfo = getTypeInfo;
|
199
|
-
var getType = function getType(type) {
|
200
|
-
switch (type) {
|
201
|
-
case 'string':
|
202
|
-
return t.tsStringKeyword();
|
203
|
-
case 'boolean':
|
204
|
-
return t.tSBooleanKeyword();
|
205
|
-
case 'integer':
|
206
|
-
return t.tsNumberKeyword();
|
207
|
-
default:
|
208
|
-
throw new Error('contact maintainers [unknown type]: ' + type);
|
209
|
-
}
|
210
|
-
};
|
211
|
-
exports.getType = getType;
|
212
|
-
var getPropertyType = function getPropertyType(context, schema, prop) {
|
213
|
-
var _schema$properties, _schema$required, _schema$required2;
|
214
|
-
var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
|
215
|
-
var info = props[prop];
|
216
|
-
var type = null;
|
217
|
-
var optional = !((_schema$required = schema.required) !== null && _schema$required !== void 0 && _schema$required.includes(prop));
|
218
|
-
if (info.allOf && info.allOf.length === 1) {
|
219
|
-
info = info.allOf[0];
|
220
|
-
}
|
221
|
-
if (typeof info.$ref === 'string') {
|
222
|
-
type = getTypeFromRef(info.$ref);
|
223
|
-
}
|
224
|
-
var typeInfo = getTypeInfo(info);
|
225
|
-
if (typeof typeInfo.optional !== 'undefined') {
|
226
|
-
optional = typeInfo.optional;
|
227
|
-
}
|
228
|
-
if (typeof typeInfo.type !== 'undefined') {
|
229
|
-
type = typeInfo.type;
|
230
|
-
}
|
231
|
-
if (!type) {
|
232
|
-
throw new Error('cannot find type for ' + JSON.stringify(info));
|
233
|
-
}
|
234
|
-
if ((_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(prop)) {
|
235
|
-
optional = false;
|
236
|
-
}
|
237
|
-
return {
|
238
|
-
type: type,
|
239
|
-
optional: optional
|
240
|
-
};
|
241
|
-
};
|
242
|
-
exports.getPropertyType = getPropertyType;
|
243
|
-
function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
244
|
-
if (jsonschema.properties[prop].type === 'object') {
|
245
|
-
if (jsonschema.properties[prop].title) {
|
246
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
|
247
|
-
} else {
|
248
|
-
throw new Error('getPropertySignatureFromProp() contact maintainer');
|
249
|
-
}
|
250
|
-
}
|
251
|
-
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
252
|
-
var _jsonschema$required;
|
253
|
-
var isOptional = !((_jsonschema$required = jsonschema.required) !== null && _jsonschema$required !== void 0 && _jsonschema$required.includes(prop));
|
254
|
-
var unionTypes = jsonschema.properties[prop].allOf.map(function (el) {
|
255
|
-
if (el.title) return el.title;
|
256
|
-
if (el.$ref) return getTypeStrFromRef(el.$ref);
|
257
|
-
return el.type;
|
258
|
-
});
|
259
|
-
// @ts-ignore:next-line
|
260
|
-
var uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(unionTypes));
|
261
|
-
if (uniqUnionTypes.length === 1) {
|
262
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
263
|
-
} else {
|
264
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(function (typ) {
|
265
|
-
return t.tsTypeReference(t.identifier(typ));
|
266
|
-
}))), isOptional);
|
267
|
-
}
|
268
|
-
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
269
|
-
var _jsonschema$required2;
|
270
|
-
var _isOptional = !((_jsonschema$required2 = jsonschema.required) !== null && _jsonschema$required2 !== void 0 && _jsonschema$required2.includes(prop));
|
271
|
-
var _unionTypes = jsonschema.properties[prop].oneOf.map(function (el) {
|
272
|
-
if (el.title) return el.title;
|
273
|
-
if (el.$ref) return getTypeStrFromRef(el.$ref);
|
274
|
-
return el.type;
|
275
|
-
});
|
276
|
-
// @ts-ignore:next-line
|
277
|
-
var _uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(_unionTypes));
|
278
|
-
if (_uniqUnionTypes.length === 1) {
|
279
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(_uniqUnionTypes[0]))), _isOptional);
|
280
|
-
} else {
|
281
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(_uniqUnionTypes.map(function (typ) {
|
282
|
-
return t.tsTypeReference(t.identifier(typ));
|
283
|
-
}))), _isOptional);
|
284
|
-
}
|
285
|
-
}
|
286
|
-
try {
|
287
|
-
getPropertyType(context, jsonschema, prop);
|
288
|
-
} catch (e) {
|
289
|
-
console.log(e);
|
290
|
-
console.log(JSON.stringify(jsonschema, null, 2), prop);
|
291
|
-
}
|
292
|
-
var _getPropertyType = getPropertyType(context, jsonschema, prop),
|
293
|
-
type = _getPropertyType.type,
|
294
|
-
optional = _getPropertyType.optional;
|
295
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
296
|
-
}
|
297
|
-
var getParamsTypeAnnotation = function getParamsTypeAnnotation(context, jsonschema) {
|
298
|
-
var _jsonschema$propertie;
|
299
|
-
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
300
|
-
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
|
301
|
-
if (!keys.length && jsonschema.$ref) {
|
302
|
-
return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
|
303
|
-
}
|
304
|
-
if (!keys.length) return undefined;
|
305
|
-
var typedParams = keys.map(function (prop) {
|
306
|
-
return getPropertySignatureFromProp(context, jsonschema, prop, camelize);
|
307
|
-
});
|
308
|
-
return t.tsTypeAnnotation(t.tsTypeLiteral( // @ts-ignore:next-line
|
309
|
-
(0, _toConsumableArray2["default"])(typedParams)));
|
310
|
-
};
|
311
|
-
exports.getParamsTypeAnnotation = getParamsTypeAnnotation;
|
312
|
-
var createTypedObjectParams = function createTypedObjectParams(context, jsonschema) {
|
313
|
-
var _jsonschema$propertie2;
|
314
|
-
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
315
|
-
var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
|
316
|
-
if (!keys.length) {
|
317
|
-
// is there a ref?
|
318
|
-
if (jsonschema.$ref) {
|
319
|
-
var _obj = context.refLookup(jsonschema.$ref);
|
320
|
-
// If there is a oneOf, then we need to create a type for it
|
321
|
-
if (_obj !== null && _obj !== void 0 && _obj.oneOf) {
|
322
|
-
// the actual type of the ref
|
323
|
-
var refType = jsonschema.$ref.split('/').pop();
|
324
|
-
var refName = (0, _case.camel)(refType);
|
325
|
-
var id = t.identifier(refName);
|
326
|
-
id.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(refType)));
|
327
|
-
return id;
|
328
|
-
} else if (_obj) {
|
329
|
-
return createTypedObjectParams(context, _obj, camelize);
|
330
|
-
}
|
331
|
-
}
|
332
|
-
|
333
|
-
// no results...
|
334
|
-
return;
|
335
|
-
}
|
336
|
-
var params = keys.map(function (prop) {
|
337
|
-
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);
|
338
|
-
});
|
339
|
-
var obj = t.objectPattern((0, _toConsumableArray2["default"])(params));
|
340
|
-
obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
|
341
|
-
return obj;
|
342
|
-
};
|
343
|
-
exports.createTypedObjectParams = createTypedObjectParams;
|
package/module/client/client.js
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
import * as t from '@babel/types';
|
2
|
-
import { camel } from 'case';
|
3
|
-
import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, FIXED_EXECUTE_PARAMS, getMessageProperties, OPTIONAL_FUNDS_PARAM, promiseTypeAnnotation, typedIdentifier } from '../utils';
|
4
|
-
import { createTypedObjectParams, getPropertyType, getResponseType, getType } 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), OPTIONAL_FUNDS_PARAM];
|
7
|
-
export const createWasmQueryMethod = (context, jsonschema) => {
|
8
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
9
|
-
const methodName = camel(underscoreName);
|
10
|
-
const responseType = getResponseType(context, underscoreName);
|
11
|
-
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
12
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
13
|
-
const msgAction = t.identifier(underscoreName);
|
14
|
-
// If the param is an identifier, we can just use it as is
|
15
|
-
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
|
16
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [param] : [], 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([t.objectProperty(msgAction, msgActionValue)])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
|
17
|
-
};
|
18
|
-
export const createQueryClass = (context, className, implementsClassName, queryMsg) => {
|
19
|
-
context.addUtil('CosmWasmClient');
|
20
|
-
const propertyNames = getMessageProperties(queryMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
21
|
-
const bindings = propertyNames.map(camel).map(bindMethod);
|
22
|
-
const methods = getMessageProperties(queryMsg).map(schema => {
|
23
|
-
return createWasmQueryMethod(context, schema);
|
24
|
-
});
|
25
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
26
|
-
// client
|
27
|
-
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
|
28
|
-
// contractAddress
|
29
|
-
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())),
|
30
|
-
// constructor
|
31
|
-
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([
|
32
|
-
// client/contract set
|
33
|
-
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))]));
|
34
|
-
};
|
35
|
-
export const getWasmMethodArgs = (context, jsonschema) => {
|
36
|
-
let keys = Object.keys(jsonschema.properties ?? {});
|
37
|
-
|
38
|
-
// only 1 degree $ref-lookup
|
39
|
-
if (!keys.length && jsonschema.$ref) {
|
40
|
-
const obj = context.refLookup(jsonschema.$ref);
|
41
|
-
// properties
|
42
|
-
if (obj) {
|
43
|
-
keys = Object.keys(obj.properties ?? {});
|
44
|
-
}
|
45
|
-
|
46
|
-
// tuple struct or otherwise, use the name of the reference
|
47
|
-
if (!keys.length && obj?.oneOf) {
|
48
|
-
// TODO????? ADAIR
|
49
|
-
}
|
50
|
-
}
|
51
|
-
const args = keys.map(prop => {
|
52
|
-
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
|
53
|
-
});
|
54
|
-
return args;
|
55
|
-
};
|
56
|
-
export const createWasmExecMethod = (context, jsonschema) => {
|
57
|
-
context.addUtil('ExecuteResult');
|
58
|
-
context.addUtil('StdFee');
|
59
|
-
context.addUtil('Coin');
|
60
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
61
|
-
const methodName = camel(underscoreName);
|
62
|
-
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
63
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
64
|
-
const msgAction = t.identifier(underscoreName);
|
65
|
-
// If the param is an identifier, we can just use it as is
|
66
|
-
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
|
67
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [
|
68
|
-
// props
|
69
|
-
param, ...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(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('_funds')])))]),
|
70
|
-
// return type
|
71
|
-
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
|
72
|
-
};
|
73
|
-
export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
|
74
|
-
context.addUtil('SigningCosmWasmClient');
|
75
|
-
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
76
|
-
const bindings = propertyNames.map(camel).map(bindMethod);
|
77
|
-
const methods = getMessageProperties(execMsg).map(schema => {
|
78
|
-
return createWasmExecMethod(context, schema);
|
79
|
-
});
|
80
|
-
const blockStmt = [];
|
81
|
-
if (extendsClassName) {
|
82
|
-
blockStmt.push(
|
83
|
-
// super()
|
84
|
-
t.expressionStatement(t.callExpression(t.super(), [t.identifier('client'), t.identifier('contractAddress')])));
|
85
|
-
}
|
86
|
-
[].push.apply(blockStmt, [
|
87
|
-
// client/contract set
|
88
|
-
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), 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'))), ...bindings]);
|
89
|
-
const noImplicitOverride = context.options.client.noImplicitOverride && extendsClassName && context.options.client.execExtendsQuery;
|
90
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
91
|
-
// client
|
92
|
-
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient'))), false, false, noImplicitOverride),
|
93
|
-
// sender
|
94
|
-
classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
95
|
-
// contractAddress
|
96
|
-
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()), false, false, noImplicitOverride),
|
97
|
-
// constructor
|
98
|
-
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));
|
99
|
-
};
|
100
|
-
export const createExecuteInterface = (context, className, extendsClassName, execMsg) => {
|
101
|
-
const methods = getMessageProperties(execMsg).map(jsonschema => {
|
102
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
103
|
-
const methodName = camel(underscoreName);
|
104
|
-
return createPropertyFunctionWithObjectParamsForExec(context, methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
105
|
-
});
|
106
|
-
const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
|
107
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
108
|
-
// contract address
|
109
|
-
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
110
|
-
// contract address
|
111
|
-
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
112
|
-
};
|
113
|
-
export const createPropertyFunctionWithObjectParams = (context, methodName, responseType, jsonschema) => {
|
114
|
-
const obj = createTypedObjectParams(context, jsonschema);
|
115
|
-
const func = {
|
116
|
-
type: 'TSFunctionType',
|
117
|
-
typeAnnotation: promiseTypeAnnotation(responseType),
|
118
|
-
parameters: obj ? [obj] : []
|
119
|
-
};
|
120
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
121
|
-
// @ts-ignore:next-line
|
122
|
-
func));
|
123
|
-
};
|
124
|
-
export const createPropertyFunctionWithObjectParamsForExec = (context, methodName, responseType, jsonschema) => {
|
125
|
-
context.addUtil('Coin');
|
126
|
-
const obj = createTypedObjectParams(context, jsonschema);
|
127
|
-
const func = {
|
128
|
-
type: 'TSFunctionType',
|
129
|
-
typeAnnotation: promiseTypeAnnotation(responseType),
|
130
|
-
parameters: obj ? [obj, ...FIXED_EXECUTE_PARAMS] : FIXED_EXECUTE_PARAMS
|
131
|
-
};
|
132
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
133
|
-
// @ts-ignore:next-line
|
134
|
-
func));
|
135
|
-
};
|
136
|
-
export const createQueryInterface = (context, className, queryMsg) => {
|
137
|
-
const methods = getMessageProperties(queryMsg).map(jsonschema => {
|
138
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
139
|
-
const methodName = camel(underscoreName);
|
140
|
-
const responseType = getResponseType(context, underscoreName);
|
141
|
-
return createPropertyFunctionWithObjectParams(context, methodName, responseType, jsonschema.properties[underscoreName]);
|
142
|
-
});
|
143
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
144
|
-
};
|
145
|
-
export const createTypeOrInterface = (context, Type, jsonschema) => {
|
146
|
-
if (jsonschema.type !== 'object') {
|
147
|
-
if (!jsonschema.type) {
|
148
|
-
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
149
|
-
}
|
150
|
-
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
|
151
|
-
}
|
152
|
-
const props = Object.keys(jsonschema.properties ?? {}).map(prop => {
|
153
|
-
const {
|
154
|
-
type,
|
155
|
-
optional
|
156
|
-
} = getPropertyType(context, jsonschema, prop);
|
157
|
-
return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
|
158
|
-
});
|
159
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody(
|
160
|
-
// @ts-ignore:next-line
|
161
|
-
[...props])));
|
162
|
-
};
|
163
|
-
export const createTypeInterface = (context, jsonschema) => {
|
164
|
-
const Type = jsonschema.title;
|
165
|
-
return createTypeOrInterface(context, Type, jsonschema);
|
166
|
-
};
|
package/module/client/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './client';
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import contract from '../../../../../__fixtures__/idl-version/accounts-nft/account-nft.json';
|
2
|
-
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
-
const message = contract.query;
|
5
|
-
const ctx = makeContext(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
|
-
|
13
|
-
// it('query classes response', () => {
|
14
|
-
// expectCode(createTypeInterface(
|
15
|
-
// ctx,
|
16
|
-
// contract.responses.all_debt_shares
|
17
|
-
// ))
|
18
|
-
// });
|
19
|
-
|
20
|
-
it('execute classes array types', () => {
|
21
|
-
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, message));
|
22
|
-
});
|
23
|
-
it('execute interfaces no extends', () => {
|
24
|
-
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, message));
|
25
|
-
});
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import message from '../../../../../__fixtures__/misc/schema/arrays-ref.json';
|
2
|
-
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
-
const ctx = makeContext(message);
|
5
|
-
it('execute_msg_for__empty', () => {
|
6
|
-
expectCode(createTypeInterface(ctx, message));
|
7
|
-
});
|
8
|
-
it('query classes', () => {
|
9
|
-
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
|
10
|
-
});
|
11
|
-
it('execute classes array types', () => {
|
12
|
-
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, message));
|
13
|
-
});
|
14
|
-
it('execute interfaces no extends', () => {
|
15
|
-
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, message));
|
16
|
-
});
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import message from '../../../../../__fixtures__/misc/schema/arrays.json';
|
2
|
-
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
-
import { getPropertyType } from '../../utils';
|
5
|
-
const ctx = makeContext(message);
|
6
|
-
it('getPropertyType', () => {
|
7
|
-
const ast = getPropertyType(ctx, message.oneOf[0].properties.update_edges, 'edges3');
|
8
|
-
expectCode(ast.type);
|
9
|
-
// printCode(ast.type)
|
10
|
-
});
|
11
|
-
|
12
|
-
it('execute_msg_for__empty', () => {
|
13
|
-
expectCode(createTypeInterface(ctx, message));
|
14
|
-
});
|
15
|
-
it('query classes', () => {
|
16
|
-
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
|
17
|
-
});
|
18
|
-
it('execute classes array types', () => {
|
19
|
-
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, message));
|
20
|
-
});
|
21
|
-
it('execute interfaces no extends', () => {
|
22
|
-
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, message));
|
23
|
-
});
|