wasm-ast-types 0.23.1 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- package/main/context/context.js +49 -5
- package/main/context/imports.js +42 -7
- package/main/index.js +13 -0
- package/main/provider/index.js +18 -0
- package/main/provider/provider.js +98 -0
- package/main/provider/provider.spec.js +63 -0
- package/main/utils/constants.js +9 -2
- package/main/utils/index.js +8 -1
- package/module/context/context.js +38 -4
- package/module/context/imports.js +35 -5
- package/module/index.js +2 -1
- package/module/provider/index.js +1 -0
- package/module/provider/provider.js +53 -0
- package/module/provider/provider.spec.js +58 -0
- package/module/utils/constants.js +7 -1
- package/module/utils/index.js +2 -1
- package/package.json +2 -2
- package/src/context/context.ts +59 -4
- package/src/context/imports.ts +84 -49
- package/src/index.ts +1 -0
- package/src/provider/__snapshots__/provider.spec.ts.snap +49 -0
- package/src/provider/index.ts +1 -0
- package/src/provider/provider.spec.ts +81 -0
- package/src/provider/provider.ts +237 -0
- package/src/react-query/react-query.ts +3 -3
- package/src/utils/constants.ts +7 -0
- package/src/utils/index.ts +1 -0
- package/types/context/context.d.ts +34 -3
- package/types/context/imports.d.ts +3 -1
- package/types/index.d.ts +1 -0
- package/types/provider/index.d.ts +1 -0
- package/types/provider/provider.d.ts +18 -0
- package/types/utils/constants.d.ts +6 -0
- package/types/utils/index.d.ts +1 -0
package/main/context/context.js
CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
|
-
exports.getDefinitionSchema = exports.defaultOptions = exports.RenderContextBase = exports.RenderContext = void 0;
|
8
|
+
exports.getDefinitionSchema = exports.defaultOptions = exports.RenderContextBase = exports.RenderContext = exports.BuilderContext = void 0;
|
9
9
|
|
10
10
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
11
11
|
|
@@ -25,6 +25,8 @@ var _imports = require("./imports");
|
|
25
25
|
|
26
26
|
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
27
27
|
|
28
|
+
var _path = require("path");
|
29
|
+
|
28
30
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
29
31
|
|
30
32
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
@@ -76,6 +78,36 @@ var getDefinitionSchema = function getDefinitionSchema(schemas) {
|
|
76
78
|
});
|
77
79
|
return aggregateSchema;
|
78
80
|
};
|
81
|
+
|
82
|
+
exports.getDefinitionSchema = getDefinitionSchema;
|
83
|
+
|
84
|
+
var BuilderContext = /*#__PURE__*/function () {
|
85
|
+
function BuilderContext() {
|
86
|
+
(0, _classCallCheck2["default"])(this, BuilderContext);
|
87
|
+
(0, _defineProperty2["default"])(this, "providers", {});
|
88
|
+
}
|
89
|
+
|
90
|
+
(0, _createClass2["default"])(BuilderContext, [{
|
91
|
+
key: "addProviderInfo",
|
92
|
+
value: function addProviderInfo(contractName, type, classname, filename) {
|
93
|
+
if (!this.providers[contractName]) {
|
94
|
+
this.providers[contractName] = {};
|
95
|
+
}
|
96
|
+
|
97
|
+
this.providers[contractName][type] = {
|
98
|
+
classname: classname,
|
99
|
+
filename: filename,
|
100
|
+
basename: (0, _path.basename)(filename, (0, _path.extname)(filename))
|
101
|
+
};
|
102
|
+
}
|
103
|
+
}, {
|
104
|
+
key: "getProviderInfos",
|
105
|
+
value: function getProviderInfos() {
|
106
|
+
return this.providers;
|
107
|
+
}
|
108
|
+
}]);
|
109
|
+
return BuilderContext;
|
110
|
+
}();
|
79
111
|
/**
|
80
112
|
* context object for generating code.
|
81
113
|
* only mergeDefaultOpt needs to implementing for combine options and default options.
|
@@ -83,11 +115,12 @@ var getDefinitionSchema = function getDefinitionSchema(schemas) {
|
|
83
115
|
*/
|
84
116
|
|
85
117
|
|
86
|
-
exports.
|
118
|
+
exports.BuilderContext = BuilderContext;
|
87
119
|
|
88
120
|
var RenderContextBase = /*#__PURE__*/function () {
|
89
|
-
function RenderContextBase(contract, options) {
|
121
|
+
function RenderContextBase(contract, options, builderContext) {
|
90
122
|
(0, _classCallCheck2["default"])(this, RenderContextBase);
|
123
|
+
(0, _defineProperty2["default"])(this, "builderContext", void 0);
|
91
124
|
(0, _defineProperty2["default"])(this, "contract", void 0);
|
92
125
|
(0, _defineProperty2["default"])(this, "utils", []);
|
93
126
|
(0, _defineProperty2["default"])(this, "schema", void 0);
|
@@ -95,6 +128,7 @@ var RenderContextBase = /*#__PURE__*/function () {
|
|
95
128
|
this.contract = contract;
|
96
129
|
this.schema = getDefinitionSchema(contract.schemas);
|
97
130
|
this.options = this.mergeDefaultOpt(options);
|
131
|
+
this.builderContext = builderContext;
|
98
132
|
}
|
99
133
|
/**
|
100
134
|
* merge options and default options
|
@@ -112,10 +146,20 @@ var RenderContextBase = /*#__PURE__*/function () {
|
|
112
146
|
value: function addUtil(util) {
|
113
147
|
this.utils[util] = true;
|
114
148
|
}
|
149
|
+
}, {
|
150
|
+
key: "addProviderInfo",
|
151
|
+
value: function addProviderInfo(contractName, type, classname, filename) {
|
152
|
+
this.builderContext.addProviderInfo(contractName, type, classname, filename);
|
153
|
+
}
|
154
|
+
}, {
|
155
|
+
key: "getProviderInfos",
|
156
|
+
value: function getProviderInfos() {
|
157
|
+
return this.builderContext.providers;
|
158
|
+
}
|
115
159
|
}, {
|
116
160
|
key: "getImports",
|
117
|
-
value: function getImports(registeredUtils) {
|
118
|
-
return (0, _imports.getImportStatements)((0, _imports.convertUtilsToImportList)(this, Object.keys(this.utils), registeredUtils));
|
161
|
+
value: function getImports(registeredUtils, filepath) {
|
162
|
+
return (0, _imports.getImportStatements)((0, _imports.convertUtilsToImportList)(this, Object.keys(this.utils), registeredUtils), filepath);
|
119
163
|
}
|
120
164
|
}]);
|
121
165
|
return RenderContextBase;
|
package/main/context/imports.js
CHANGED
@@ -7,18 +7,26 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
9
9
|
});
|
10
|
-
exports.getImportStatements = exports.convertUtilsToImportList = exports.convertUtil = exports.UTILS = void 0;
|
10
|
+
exports.getRelativePath = exports.getImportStatements = exports.convertUtilsToImportList = exports.convertUtil = exports.UTIL_HELPERS = exports.UTILS = void 0;
|
11
11
|
|
12
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
13
13
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
+
|
14
16
|
var t = _interopRequireWildcard(require("@babel/types"));
|
15
17
|
|
16
18
|
var _utils = require("../utils");
|
17
19
|
|
20
|
+
var _path = require("path");
|
21
|
+
|
18
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); }
|
19
23
|
|
20
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; }
|
21
25
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
27
|
+
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
29
|
+
|
22
30
|
var makeReactQuerySwitch = function makeReactQuerySwitch(varName) {
|
23
31
|
return function (context) {
|
24
32
|
switch (context.options.reactQuery.version) {
|
@@ -57,6 +65,8 @@ var UTILS = {
|
|
57
65
|
UseMutationOptions: makeReactQuerySwitch('UseMutationOptions')
|
58
66
|
};
|
59
67
|
exports.UTILS = UTILS;
|
68
|
+
var UTIL_HELPERS = ['__contractContextBase__'];
|
69
|
+
exports.UTIL_HELPERS = UTIL_HELPERS;
|
60
70
|
|
61
71
|
var convertUtilsToImportList = function convertUtilsToImportList(context, utils, registeredUtils) {
|
62
72
|
return utils.map(function (util) {
|
@@ -96,22 +106,38 @@ var convertUtil = function convertUtil(context, util, registeredUtils) {
|
|
96
106
|
} else {
|
97
107
|
return registeredUtils[util];
|
98
108
|
}
|
99
|
-
};
|
109
|
+
}; // __helpers__
|
110
|
+
|
100
111
|
|
101
112
|
exports.convertUtil = convertUtil;
|
102
113
|
|
103
|
-
var getImportStatements = function getImportStatements(list) {
|
104
|
-
|
114
|
+
var getImportStatements = function getImportStatements(list, filepath) {
|
115
|
+
// swap helpers with helpers file...
|
116
|
+
var modifiedImports = list.map(function (imp) {
|
117
|
+
if (filepath && UTIL_HELPERS.includes(imp.path)) {
|
118
|
+
var name = imp.path.replace(/__/g, '');
|
119
|
+
return _objectSpread(_objectSpread({}, imp), {}, {
|
120
|
+
path: getRelativePath(filepath, "./".concat(name))
|
121
|
+
});
|
122
|
+
}
|
123
|
+
|
124
|
+
return imp;
|
125
|
+
});
|
126
|
+
var imports = modifiedImports.reduce(function (m, obj) {
|
105
127
|
m[obj.path] = m[obj.path] || [];
|
106
128
|
var exists = m[obj.path].find(function (el) {
|
107
129
|
return el.type === obj.type && el.path === obj.path && el.name === obj.name;
|
108
|
-
}); //
|
130
|
+
}); // MARKED AS NOT DRY [google.protobuf names]
|
131
|
+
// TODO some have google.protobuf.Any shows up... figure out the better way to handle this
|
109
132
|
|
110
133
|
if (/\./.test(obj.name)) {
|
111
134
|
obj.name = obj.name.split('.')[obj.name.split('.').length - 1];
|
112
135
|
}
|
113
136
|
|
114
|
-
if (!exists)
|
137
|
+
if (!exists) {
|
138
|
+
m[obj.path].push(obj);
|
139
|
+
}
|
140
|
+
|
115
141
|
return m;
|
116
142
|
}, {});
|
117
143
|
return Object.entries(imports).reduce(function (m, _ref) {
|
@@ -157,4 +183,13 @@ var getImportStatements = function getImportStatements(list) {
|
|
157
183
|
}, []);
|
158
184
|
};
|
159
185
|
|
160
|
-
exports.getImportStatements = getImportStatements;
|
186
|
+
exports.getImportStatements = getImportStatements;
|
187
|
+
|
188
|
+
var getRelativePath = function getRelativePath(f1, f2) {
|
189
|
+
var rel = (0, _path.relative)((0, _path.dirname)(f1), f2);
|
190
|
+
var importPath = rel.replace((0, _path.extname)(rel), '');
|
191
|
+
if (!/^\./.test(importPath)) importPath = "./".concat(importPath);
|
192
|
+
return importPath;
|
193
|
+
};
|
194
|
+
|
195
|
+
exports.getRelativePath = getRelativePath;
|
package/main/index.js
CHANGED
@@ -106,4 +106,17 @@ Object.keys(_msgBuilder).forEach(function (key) {
|
|
106
106
|
return _msgBuilder[key];
|
107
107
|
}
|
108
108
|
});
|
109
|
+
});
|
110
|
+
|
111
|
+
var _provider = require("./provider");
|
112
|
+
|
113
|
+
Object.keys(_provider).forEach(function (key) {
|
114
|
+
if (key === "default" || key === "__esModule") return;
|
115
|
+
if (key in exports && exports[key] === _provider[key]) return;
|
116
|
+
Object.defineProperty(exports, key, {
|
117
|
+
enumerable: true,
|
118
|
+
get: function get() {
|
119
|
+
return _provider[key];
|
120
|
+
}
|
121
|
+
});
|
109
122
|
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _provider = require("./provider");
|
8
|
+
|
9
|
+
Object.keys(_provider).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _provider[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _provider[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createProvider = exports.createProperty = exports.createIContractsContext = exports.createGettingProviders = void 0;
|
9
|
+
|
10
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
11
|
+
|
12
|
+
var _case = require("case");
|
13
|
+
|
14
|
+
var _constants = require("../utils/constants");
|
15
|
+
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
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); }
|
19
|
+
|
20
|
+
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; }
|
21
|
+
|
22
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
23
|
+
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
25
|
+
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
27
|
+
|
28
|
+
var createProvider = function createProvider(name, providerInfos) {
|
29
|
+
var classDeclaration = t.classDeclaration(t.identifier(name), t.identifier("ContractBase"), t.classBody([t.classMethod("constructor", t.identifier("constructor"), [(0, _utils.tsObjectPattern)([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)], t.tsTypeAnnotation(t.tsTypeReference(t.identifier("IContractConstructor"))))], t.blockStatement([t.expressionStatement(t.callExpression(t["super"](), [t.identifier("address"), t.identifier("cosmWasmClient"), t.identifier("signingCosmWasmClient"), t.identifier(providerInfos[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "undefined")]))]))]));
|
30
|
+
classDeclaration.superTypeParameters = t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "IEmptyClient"))]);
|
31
|
+
return t.exportNamedDeclaration(classDeclaration);
|
32
|
+
};
|
33
|
+
|
34
|
+
exports.createProvider = createProvider;
|
35
|
+
|
36
|
+
var createIContractsContext = function createIContractsContext(providerInfos) {
|
37
|
+
var properties = [];
|
38
|
+
|
39
|
+
for (var _key in providerInfos) {
|
40
|
+
if (Object.prototype.hasOwnProperty.call(providerInfos, _key)) {
|
41
|
+
var contractProviderInfo = providerInfos[_key];
|
42
|
+
properties.push(createProperty(_key, contractProviderInfo));
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier("IContractsContext"), null, null, t.tsInterfaceBody(properties)));
|
47
|
+
};
|
48
|
+
|
49
|
+
exports.createIContractsContext = createIContractsContext;
|
50
|
+
var PROVIDER_MAPPING = {};
|
51
|
+
PROVIDER_MAPPING[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = "ISigningClientProvider";
|
52
|
+
PROVIDER_MAPPING[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = "IQueryClientProvider";
|
53
|
+
PROVIDER_MAPPING[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = "IMessageComposerProvider";
|
54
|
+
|
55
|
+
var createProperty = function createProperty(name, providerInfos) {
|
56
|
+
var typeAnnotation = null;
|
57
|
+
var keys = Object.keys(providerInfos);
|
58
|
+
|
59
|
+
if ((keys === null || keys === void 0 ? void 0 : keys.length) == 1) {
|
60
|
+
var _key2 = keys[0];
|
61
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[_key2]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[_key2].classname))])));
|
62
|
+
} else {
|
63
|
+
var typeRefs = [];
|
64
|
+
|
65
|
+
var _iterator = _createForOfIteratorHelper(keys),
|
66
|
+
_step;
|
67
|
+
|
68
|
+
try {
|
69
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
70
|
+
var _key3 = _step.value;
|
71
|
+
typeRefs.push(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[_key3]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[_key3].classname))])));
|
72
|
+
}
|
73
|
+
} catch (err) {
|
74
|
+
_iterator.e(err);
|
75
|
+
} finally {
|
76
|
+
_iterator.f();
|
77
|
+
}
|
78
|
+
|
79
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType(typeRefs));
|
80
|
+
}
|
81
|
+
|
82
|
+
return t.tsPropertySignature(t.identifier((0, _case.camel)(name)), typeAnnotation);
|
83
|
+
};
|
84
|
+
|
85
|
+
exports.createProperty = createProperty;
|
86
|
+
|
87
|
+
var createGettingProviders = function createGettingProviders(providerInfos) {
|
88
|
+
var properties = [];
|
89
|
+
|
90
|
+
for (var _i = 0, _Object$keys = Object.keys(providerInfos); _i < _Object$keys.length; _i++) {
|
91
|
+
var _key4 = _Object$keys[_i];
|
92
|
+
properties.push(t.objectProperty(t.identifier((0, _case.camel)(_key4)), t.newExpression(t.identifier((0, _case.pascal)(_key4)), [t.objectExpression([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)])])));
|
93
|
+
}
|
94
|
+
|
95
|
+
return t.exportNamedDeclaration(t.variableDeclaration("const", [t.variableDeclarator(t.identifier("getProviders"), t.arrowFunctionExpression([(0, _utils.identifier)("address?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("string")))), (0, _utils.identifier)("cosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("CosmWasmClient")))), (0, _utils.identifier)("signingCosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("SigningCosmWasmClient"))))], t.objectExpression(properties)))]));
|
96
|
+
};
|
97
|
+
|
98
|
+
exports.createGettingProviders = createGettingProviders;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _provider = require("./provider");
|
4
|
+
|
5
|
+
var _testUtils = require("../../test-utils");
|
6
|
+
|
7
|
+
var _constants = require("../utils/constants");
|
8
|
+
|
9
|
+
it("execute class", function () {
|
10
|
+
var info = {};
|
11
|
+
info[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
12
|
+
classname: "WhitelistClient"
|
13
|
+
};
|
14
|
+
info[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
15
|
+
classname: "WhitelistQueryClient"
|
16
|
+
};
|
17
|
+
info[_constants.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = {
|
18
|
+
classname: "WhitelistMessageComposer"
|
19
|
+
};
|
20
|
+
(0, _testUtils.expectCode)((0, _provider.createProvider)("Whitelist", info));
|
21
|
+
});
|
22
|
+
it("execute class without message composer", function () {
|
23
|
+
var info = {};
|
24
|
+
info[_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
25
|
+
classname: "WhitelistClient"
|
26
|
+
};
|
27
|
+
info[_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
28
|
+
classname: "WhitelistQueryClient"
|
29
|
+
};
|
30
|
+
(0, _testUtils.expectCode)((0, _provider.createProvider)("Whitelist", info));
|
31
|
+
});
|
32
|
+
it("create IContractsContext", function () {
|
33
|
+
var info = {
|
34
|
+
Whitelist: {},
|
35
|
+
Marketplace: {}
|
36
|
+
};
|
37
|
+
info["Whitelist"][_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
38
|
+
classname: "WhitelistClient"
|
39
|
+
};
|
40
|
+
info["Whitelist"][_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
41
|
+
classname: "WhitelistQueryClient"
|
42
|
+
};
|
43
|
+
info["Marketplace"][_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
44
|
+
classname: "MarketplaceClient"
|
45
|
+
};
|
46
|
+
(0, _testUtils.expectCode)((0, _provider.createIContractsContext)(info));
|
47
|
+
});
|
48
|
+
it("create getProviders", function () {
|
49
|
+
var info = {
|
50
|
+
Whitelist: {},
|
51
|
+
Marketplace: {}
|
52
|
+
};
|
53
|
+
info["Whitelist"][_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
54
|
+
classname: "WhitelistClient"
|
55
|
+
};
|
56
|
+
info["Whitelist"][_constants.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
57
|
+
classname: "WhitelistQueryClient"
|
58
|
+
};
|
59
|
+
info["Marketplace"][_constants.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
60
|
+
classname: "MarketplaceClient"
|
61
|
+
};
|
62
|
+
(0, _testUtils.expectCode)((0, _provider.createGettingProviders)(info));
|
63
|
+
});
|
package/main/utils/constants.js
CHANGED
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
|
-
exports.OPTIONAL_MEMO_PARAM = exports.OPTIONAL_FUNDS_PARAM = exports.OPTIONAL_FEE_PARAM = exports.FIXED_EXECUTE_PARAMS = void 0;
|
8
|
+
exports.PROVIDER_TYPES = exports.OPTIONAL_MEMO_PARAM = exports.OPTIONAL_FUNDS_PARAM = exports.OPTIONAL_FEE_PARAM = exports.FIXED_EXECUTE_PARAMS = void 0;
|
9
9
|
|
10
10
|
var _babel = require("./babel");
|
11
11
|
|
@@ -22,4 +22,11 @@ exports.OPTIONAL_FEE_PARAM = OPTIONAL_FEE_PARAM;
|
|
22
22
|
var OPTIONAL_MEMO_PARAM = (0, _babel.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true);
|
23
23
|
exports.OPTIONAL_MEMO_PARAM = OPTIONAL_MEMO_PARAM;
|
24
24
|
var FIXED_EXECUTE_PARAMS = [OPTIONAL_FEE_PARAM, OPTIONAL_MEMO_PARAM, OPTIONAL_FUNDS_PARAM];
|
25
|
-
exports.FIXED_EXECUTE_PARAMS = FIXED_EXECUTE_PARAMS;
|
25
|
+
exports.FIXED_EXECUTE_PARAMS = FIXED_EXECUTE_PARAMS;
|
26
|
+
var PROVIDER_TYPES = {
|
27
|
+
SIGNING_CLIENT_TYPE: "client",
|
28
|
+
QUERY_CLIENT_TYPE: "queryClient",
|
29
|
+
MESSAGE_COMPOSER_TYPE: 'message-composer',
|
30
|
+
PROVIDER_TYPE: 'provider'
|
31
|
+
};
|
32
|
+
exports.PROVIDER_TYPES = PROVIDER_TYPES;
|
package/main/utils/index.js
CHANGED
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
var _exportNames = {
|
7
7
|
OPTIONAL_FUNDS_PARAM: true,
|
8
|
-
FIXED_EXECUTE_PARAMS: true
|
8
|
+
FIXED_EXECUTE_PARAMS: true,
|
9
|
+
PROVIDER_TYPES: true
|
9
10
|
};
|
10
11
|
Object.defineProperty(exports, "FIXED_EXECUTE_PARAMS", {
|
11
12
|
enumerable: true,
|
@@ -19,6 +20,12 @@ Object.defineProperty(exports, "OPTIONAL_FUNDS_PARAM", {
|
|
19
20
|
return _constants.OPTIONAL_FUNDS_PARAM;
|
20
21
|
}
|
21
22
|
});
|
23
|
+
Object.defineProperty(exports, "PROVIDER_TYPES", {
|
24
|
+
enumerable: true,
|
25
|
+
get: function get() {
|
26
|
+
return _constants.PROVIDER_TYPES;
|
27
|
+
}
|
28
|
+
});
|
22
29
|
|
23
30
|
var _babel = require("./babel");
|
24
31
|
|
@@ -6,7 +6,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
6
6
|
|
7
7
|
import { refLookup } from "../utils";
|
8
8
|
import { convertUtilsToImportList, getImportStatements } from "./imports";
|
9
|
-
import deepmerge from "deepmerge";
|
9
|
+
import deepmerge from "deepmerge";
|
10
|
+
import { basename, extname } from 'path'; /// Plugin Types
|
10
11
|
|
11
12
|
;
|
12
13
|
export const defaultOptions = {
|
@@ -49,6 +50,28 @@ export const getDefinitionSchema = schemas => {
|
|
49
50
|
});
|
50
51
|
return aggregateSchema;
|
51
52
|
};
|
53
|
+
export class BuilderContext {
|
54
|
+
constructor() {
|
55
|
+
_defineProperty(this, "providers", {});
|
56
|
+
}
|
57
|
+
|
58
|
+
addProviderInfo(contractName, type, classname, filename) {
|
59
|
+
if (!this.providers[contractName]) {
|
60
|
+
this.providers[contractName] = {};
|
61
|
+
}
|
62
|
+
|
63
|
+
this.providers[contractName][type] = {
|
64
|
+
classname,
|
65
|
+
filename,
|
66
|
+
basename: basename(filename, extname(filename))
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
getProviderInfos() {
|
71
|
+
return this.providers;
|
72
|
+
}
|
73
|
+
|
74
|
+
}
|
52
75
|
/**
|
53
76
|
* context object for generating code.
|
54
77
|
* only mergeDefaultOpt needs to implementing for combine options and default options.
|
@@ -56,7 +79,9 @@ export const getDefinitionSchema = schemas => {
|
|
56
79
|
*/
|
57
80
|
|
58
81
|
export class RenderContextBase {
|
59
|
-
constructor(contract, options) {
|
82
|
+
constructor(contract, options, builderContext) {
|
83
|
+
_defineProperty(this, "builderContext", void 0);
|
84
|
+
|
60
85
|
_defineProperty(this, "contract", void 0);
|
61
86
|
|
62
87
|
_defineProperty(this, "utils", []);
|
@@ -68,6 +93,7 @@ export class RenderContextBase {
|
|
68
93
|
this.contract = contract;
|
69
94
|
this.schema = getDefinitionSchema(contract.schemas);
|
70
95
|
this.options = this.mergeDefaultOpt(options);
|
96
|
+
this.builderContext = builderContext;
|
71
97
|
}
|
72
98
|
/**
|
73
99
|
* merge options and default options
|
@@ -83,8 +109,16 @@ export class RenderContextBase {
|
|
83
109
|
this.utils[util] = true;
|
84
110
|
}
|
85
111
|
|
86
|
-
|
87
|
-
|
112
|
+
addProviderInfo(contractName, type, classname, filename) {
|
113
|
+
this.builderContext.addProviderInfo(contractName, type, classname, filename);
|
114
|
+
}
|
115
|
+
|
116
|
+
getProviderInfos() {
|
117
|
+
return this.builderContext.providers;
|
118
|
+
}
|
119
|
+
|
120
|
+
getImports(registeredUtils, filepath) {
|
121
|
+
return getImportStatements(convertUtilsToImportList(this, Object.keys(this.utils), registeredUtils), filepath);
|
88
122
|
}
|
89
123
|
|
90
124
|
}
|
@@ -1,5 +1,12 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
+
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
|
+
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
|
+
|
1
7
|
import * as t from '@babel/types';
|
2
8
|
import { importAs, importStmt } from "../utils";
|
9
|
+
import { relative, dirname, extname } from 'path';
|
3
10
|
|
4
11
|
const makeReactQuerySwitch = varName => {
|
5
12
|
return context => {
|
@@ -38,6 +45,7 @@ export const UTILS = {
|
|
38
45
|
useMutation: makeReactQuerySwitch('useMutation'),
|
39
46
|
UseMutationOptions: makeReactQuerySwitch('UseMutationOptions')
|
40
47
|
};
|
48
|
+
export const UTIL_HELPERS = ['__contractContextBase__'];
|
41
49
|
export const convertUtilsToImportList = (context, utils, registeredUtils) => {
|
42
50
|
return utils.map(util => {
|
43
51
|
let result = null;
|
@@ -73,17 +81,33 @@ export const convertUtil = (context, util, registeredUtils) => {
|
|
73
81
|
} else {
|
74
82
|
return registeredUtils[util];
|
75
83
|
}
|
76
|
-
};
|
77
|
-
|
78
|
-
|
84
|
+
}; // __helpers__
|
85
|
+
|
86
|
+
export const getImportStatements = (list, filepath) => {
|
87
|
+
// swap helpers with helpers file...
|
88
|
+
const modifiedImports = list.map(imp => {
|
89
|
+
if (filepath && UTIL_HELPERS.includes(imp.path)) {
|
90
|
+
const name = imp.path.replace(/__/g, '');
|
91
|
+
return _objectSpread(_objectSpread({}, imp), {}, {
|
92
|
+
path: getRelativePath(filepath, `./${name}`)
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
return imp;
|
97
|
+
});
|
98
|
+
const imports = modifiedImports.reduce((m, obj) => {
|
79
99
|
m[obj.path] = m[obj.path] || [];
|
80
|
-
const exists = m[obj.path].find(el => el.type === obj.type && el.path === obj.path && el.name === obj.name); //
|
100
|
+
const exists = m[obj.path].find(el => el.type === obj.type && el.path === obj.path && el.name === obj.name); // MARKED AS NOT DRY [google.protobuf names]
|
101
|
+
// TODO some have google.protobuf.Any shows up... figure out the better way to handle this
|
81
102
|
|
82
103
|
if (/\./.test(obj.name)) {
|
83
104
|
obj.name = obj.name.split('.')[obj.name.split('.').length - 1];
|
84
105
|
}
|
85
106
|
|
86
|
-
if (!exists)
|
107
|
+
if (!exists) {
|
108
|
+
m[obj.path].push(obj);
|
109
|
+
}
|
110
|
+
|
87
111
|
return m;
|
88
112
|
}, {});
|
89
113
|
return Object.entries(imports).reduce((m, [importPath, imports]) => {
|
@@ -113,4 +137,10 @@ export const getImportStatements = list => {
|
|
113
137
|
|
114
138
|
return m;
|
115
139
|
}, []);
|
140
|
+
};
|
141
|
+
export const getRelativePath = (f1, f2) => {
|
142
|
+
const rel = relative(dirname(f1), f2);
|
143
|
+
let importPath = rel.replace(extname(rel), '');
|
144
|
+
if (!/^\./.test(importPath)) importPath = `./${importPath}`;
|
145
|
+
return importPath;
|
116
146
|
};
|
package/module/index.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './provider';
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import * as t from "@babel/types";
|
2
|
+
import { camel, pascal } from "case";
|
3
|
+
import { PROVIDER_TYPES } from "../utils/constants";
|
4
|
+
import { identifier, tsObjectPattern } from "../utils";
|
5
|
+
export const createProvider = (name, providerInfos) => {
|
6
|
+
const classDeclaration = t.classDeclaration(t.identifier(name), t.identifier("ContractBase"), t.classBody([t.classMethod("constructor", t.identifier("constructor"), [tsObjectPattern([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)], t.tsTypeAnnotation(t.tsTypeReference(t.identifier("IContractConstructor"))))], t.blockStatement([t.expressionStatement(t.callExpression(t.super(), [t.identifier("address"), t.identifier("cosmWasmClient"), t.identifier("signingCosmWasmClient"), t.identifier(providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "undefined")]))]))]));
|
7
|
+
classDeclaration.superTypeParameters = t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "IEmptyClient"))]);
|
8
|
+
return t.exportNamedDeclaration(classDeclaration);
|
9
|
+
};
|
10
|
+
export const createIContractsContext = providerInfos => {
|
11
|
+
const properties = [];
|
12
|
+
|
13
|
+
for (const key in providerInfos) {
|
14
|
+
if (Object.prototype.hasOwnProperty.call(providerInfos, key)) {
|
15
|
+
const contractProviderInfo = providerInfos[key];
|
16
|
+
properties.push(createProperty(key, contractProviderInfo));
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier("IContractsContext"), null, null, t.tsInterfaceBody(properties)));
|
21
|
+
};
|
22
|
+
let PROVIDER_MAPPING = {};
|
23
|
+
PROVIDER_MAPPING[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = "ISigningClientProvider";
|
24
|
+
PROVIDER_MAPPING[PROVIDER_TYPES.QUERY_CLIENT_TYPE] = "IQueryClientProvider";
|
25
|
+
PROVIDER_MAPPING[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = "IMessageComposerProvider";
|
26
|
+
export const createProperty = (name, providerInfos) => {
|
27
|
+
let typeAnnotation = null;
|
28
|
+
const keys = Object.keys(providerInfos);
|
29
|
+
|
30
|
+
if (keys?.length == 1) {
|
31
|
+
const key = keys[0];
|
32
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
33
|
+
} else {
|
34
|
+
const typeRefs = [];
|
35
|
+
|
36
|
+
for (const key of keys) {
|
37
|
+
typeRefs.push(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
38
|
+
}
|
39
|
+
|
40
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType(typeRefs));
|
41
|
+
}
|
42
|
+
|
43
|
+
return t.tsPropertySignature(t.identifier(camel(name)), typeAnnotation);
|
44
|
+
};
|
45
|
+
export const createGettingProviders = providerInfos => {
|
46
|
+
const properties = [];
|
47
|
+
|
48
|
+
for (const key of Object.keys(providerInfos)) {
|
49
|
+
properties.push(t.objectProperty(t.identifier(camel(key)), t.newExpression(t.identifier(pascal(key)), [t.objectExpression([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)])])));
|
50
|
+
}
|
51
|
+
|
52
|
+
return t.exportNamedDeclaration(t.variableDeclaration("const", [t.variableDeclarator(t.identifier("getProviders"), t.arrowFunctionExpression([identifier("address?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("string")))), identifier("cosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("CosmWasmClient")))), identifier("signingCosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("SigningCosmWasmClient"))))], t.objectExpression(properties)))]));
|
53
|
+
};
|