@cosmwasm/ts-codegen 0.30.1 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/README.md +5 -2
  2. package/main/builder/builder.js +41 -4
  3. package/main/generators/create-helpers.js +38 -0
  4. package/main/helpers/contractContextBase.js +8 -0
  5. package/main/helpers/contractsContextTSX.js +8 -0
  6. package/main/helpers/index.js +31 -0
  7. package/main/plugins/client.js +11 -6
  8. package/main/plugins/message-composer.js +10 -6
  9. package/main/plugins/msg-builder.js +1 -1
  10. package/main/plugins/plugin-base.js +9 -2
  11. package/main/plugins/provider-bundle.js +146 -0
  12. package/main/plugins/provider.js +170 -0
  13. package/main/plugins/react-query.js +1 -1
  14. package/main/plugins/recoil.js +1 -1
  15. package/main/plugins/types.js +1 -1
  16. package/main/utils/files.js +77 -0
  17. package/main/utils/unused.js +68 -0
  18. package/module/builder/builder.js +28 -2
  19. package/module/generators/create-helpers.js +25 -0
  20. package/module/helpers/contractContextBase.js +92 -0
  21. package/module/helpers/contractsContextTSX.js +73 -0
  22. package/module/helpers/index.js +2 -0
  23. package/module/plugins/client.js +13 -10
  24. package/module/plugins/message-composer.js +12 -10
  25. package/module/plugins/msg-builder.js +1 -1
  26. package/module/plugins/plugin-base.js +15 -8
  27. package/module/plugins/provider-bundle.js +65 -0
  28. package/module/plugins/provider.js +81 -0
  29. package/module/plugins/react-query.js +1 -1
  30. package/module/plugins/recoil.js +1 -1
  31. package/module/plugins/types.js +1 -1
  32. package/module/utils/files.js +44 -0
  33. package/module/utils/unused.js +45 -0
  34. package/package.json +3 -3
  35. package/src/builder/builder.ts +36 -1
  36. package/src/generators/create-helpers.ts +28 -0
  37. package/src/helpers/contractContextBase.ts +92 -0
  38. package/src/helpers/contractsContextTSX.ts +73 -0
  39. package/src/helpers/index.ts +2 -0
  40. package/src/plugins/client.ts +30 -14
  41. package/src/plugins/message-composer.ts +23 -14
  42. package/src/plugins/msg-builder.ts +1 -1
  43. package/src/plugins/plugin-base.ts +30 -20
  44. package/src/plugins/provider-bundle.ts +97 -0
  45. package/src/plugins/provider.ts +114 -0
  46. package/src/plugins/react-query.ts +1 -1
  47. package/src/plugins/recoil.ts +1 -1
  48. package/src/plugins/types.ts +1 -1
  49. package/src/utils/files.ts +73 -0
  50. package/src/utils/unused.ts +52 -0
  51. package/types/src/builder/builder.d.ts +7 -1
  52. package/types/src/generators/create-helpers.d.ts +3 -0
  53. package/types/src/helpers/contractContextBase.d.ts +1 -0
  54. package/types/src/helpers/contractsContextTSX.d.ts +1 -0
  55. package/types/src/helpers/index.d.ts +2 -0
  56. package/types/src/plugins/client.d.ts +4 -3
  57. package/types/src/plugins/message-composer.d.ts +4 -3
  58. package/types/src/plugins/plugin-base.d.ts +7 -3
  59. package/types/src/plugins/provider-bundle.d.ts +13 -0
  60. package/types/src/plugins/provider.d.ts +15 -0
  61. package/types/src/plugins/use-contracts.d.ts +12 -0
  62. package/types/src/utils/files.d.ts +3 -0
  63. package/types/src/utils/unused.d.ts +5 -0
package/README.md CHANGED
@@ -507,8 +507,11 @@ See the [docs](https://github.com/CosmWasm/ts-codegen/blob/main/packages/wasm-as
507
507
  Checkout these related projects:
508
508
 
509
509
  * [@osmonauts/telescope](https://github.com/osmosis-labs/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
510
- * [chain-registry](https://github.com/cosmology-tech/chain-registry) Cosmos chain registry and chain info.
511
- * [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos.
510
+ * [chain-registry](https://github.com/cosmology-tech/chain-registry) an npm module for the official Cosmos chain-registry.
511
+ * [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos ⚛️
512
+ * [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) set up a modern Cosmos app by running one command.
513
+ * [starship](https://github.com/cosmology-tech/starship) a k8s-based unified development environment for Cosmos Ecosystem
514
+
512
515
  ## Credits
513
516
 
514
517
  🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)
@@ -55,6 +55,12 @@ var _client = require("../plugins/client");
55
55
 
56
56
  var _types2 = require("../plugins/types");
57
57
 
58
+ var _provider = require("../plugins/provider");
59
+
60
+ var _createHelpers = require("../generators/create-helpers");
61
+
62
+ var _providerBundle = require("../plugins/provider-bundle");
63
+
58
64
  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); }
59
65
 
60
66
  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; }
@@ -75,6 +81,7 @@ var defaultOpts = {
75
81
  ;
76
82
  ;
77
83
  ;
84
+ ;
78
85
 
79
86
  function getContract(contractOpt) {
80
87
  if (typeof contractOpt === 'string') {
@@ -94,6 +101,8 @@ function getContract(contractOpt) {
94
101
 
95
102
  var TSBuilder = /*#__PURE__*/function () {
96
103
  function TSBuilder(_ref) {
104
+ var _this = this;
105
+
97
106
  var contracts = _ref.contracts,
98
107
  outPath = _ref.outPath,
99
108
  options = _ref.options,
@@ -103,6 +112,7 @@ var TSBuilder = /*#__PURE__*/function () {
103
112
  (0, _defineProperty2["default"])(this, "outPath", void 0);
104
113
  (0, _defineProperty2["default"])(this, "options", void 0);
105
114
  (0, _defineProperty2["default"])(this, "plugins", []);
115
+ (0, _defineProperty2["default"])(this, "builderContext", new _wasmAstTypes.BuilderContext());
106
116
  (0, _defineProperty2["default"])(this, "files", []);
107
117
  this.contracts = contracts;
108
118
  this.outPath = outPath;
@@ -112,12 +122,16 @@ var TSBuilder = /*#__PURE__*/function () {
112
122
  if (plugins && plugins.length) {
113
123
  [].push.apply(this.plugins, plugins);
114
124
  }
125
+
126
+ this.plugins.forEach(function (plugin) {
127
+ return plugin.setBuilder(_this);
128
+ });
115
129
  }
116
130
 
117
131
  (0, _createClass2["default"])(TSBuilder, [{
118
132
  key: "loadDefaultPlugins",
119
133
  value: function loadDefaultPlugins() {
120
- [].push.apply(this.plugins, [new _types2.TypesPlugin(this.options), new _client.ClientPlugin(this.options), new _messageComposer.MessageComposerPlugin(this.options), new _reactQuery.ReactQueryPlugin(this.options), new _recoil.RecoilPlugin(this.options), new _msgBuilder.MsgBuilderPlugin(this.options)]);
134
+ [].push.apply(this.plugins, [new _types2.TypesPlugin(this.options), new _client.ClientPlugin(this.options), new _messageComposer.MessageComposerPlugin(this.options), new _reactQuery.ReactQueryPlugin(this.options), new _recoil.RecoilPlugin(this.options), new _msgBuilder.MsgBuilderPlugin(this.options), new _provider.ContractsContextProviderPlugin(this.options)]);
121
135
  }
122
136
  }, {
123
137
  key: "build",
@@ -289,15 +303,38 @@ var TSBuilder = /*#__PURE__*/function () {
289
303
  key: "after",
290
304
  value: function () {
291
305
  var _after = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
306
+ var contractsProviderBundlePlugin, files;
292
307
  return _regenerator["default"].wrap(function _callee4$(_context4) {
293
308
  while (1) {
294
309
  switch (_context4.prev = _context4.next) {
295
310
  case 0:
296
311
  if (this.options.bundle.enabled) {
297
312
  this.bundle();
313
+ } //create useContracts bundle file
314
+
315
+
316
+ contractsProviderBundlePlugin = new _providerBundle.ContractsProviderBundlePlugin(this.options);
317
+ contractsProviderBundlePlugin.setBuilder(this);
318
+ _context4.next = 5;
319
+ return contractsProviderBundlePlugin.render("", {
320
+ schemas: []
321
+ }, this.outPath);
322
+
323
+ case 5:
324
+ files = _context4.sent;
325
+
326
+ if (files && files.length) {
327
+ [].push.apply(this.files, files);
298
328
  }
299
329
 
300
- case 1:
330
+ (0, _createHelpers.createHelpers)({
331
+ outPath: this.outPath,
332
+ contracts: this.contracts,
333
+ options: this.options,
334
+ plugins: this.plugins
335
+ }, this.builderContext);
336
+
337
+ case 8:
301
338
  case "end":
302
339
  return _context4.stop();
303
340
  }
@@ -318,7 +355,7 @@ var TSBuilder = /*#__PURE__*/function () {
318
355
  var _this$options$bundle$,
319
356
  _this$options,
320
357
  _this$options$bundle,
321
- _this = this,
358
+ _this2 = this,
322
359
  _this$options2,
323
360
  _this$options2$bundle;
324
361
 
@@ -334,7 +371,7 @@ var TSBuilder = /*#__PURE__*/function () {
334
371
  bundleVariables = {};
335
372
  importPaths = [];
336
373
  allFiles.forEach(function (file) {
337
- (0, _bundler.createFileBundle)("".concat(_this.options.bundle.scope, ".").concat(file.contract), file.filename, bundlePath, importPaths, bundleVariables);
374
+ (0, _bundler.createFileBundle)("".concat(_this2.options.bundle.scope, ".").concat(file.contract), file.filename, bundlePath, importPaths, bundleVariables);
338
375
  });
339
376
  ast = (0, _bundler.recursiveModuleBundle)(bundleVariables);
340
377
  code = (0, _generator["default"])(t.program([].concat(importPaths, (0, _toConsumableArray2["default"])(ast)))).code;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createHelpers = void 0;
9
+
10
+ var _path = require("path");
11
+
12
+ var _mkdirp = require("mkdirp");
13
+
14
+ var _package = _interopRequireDefault(require("../../package.json"));
15
+
16
+ var _files = require("../utils/files");
17
+
18
+ var _helpers = require("../helpers");
19
+
20
+ var version = process.env.NODE_ENV === "test" ? "latest" : _package["default"].version;
21
+ var header = "/**\n* This file and any referenced files were automatically generated by ".concat(_package["default"].name, "@").concat(version, "\n* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain\n* and run the transpile command or yarn proto command to regenerate this bundle.\n*/\n\n");
22
+
23
+ var write = function write(outPath, file, content) {
24
+ var outFile = (0, _path.join)(outPath, file);
25
+ (0, _mkdirp.sync)((0, _path.dirname)(outFile));
26
+ (0, _files.writeContentToFile)(outPath, header + content, outFile);
27
+ };
28
+
29
+ var createHelpers = function createHelpers(input, builderContext) {
30
+ var _input$options, _input$options$useCon, _Object$keys;
31
+
32
+ if ((_input$options = input.options) !== null && _input$options !== void 0 && (_input$options$useCon = _input$options.useContracts) !== null && _input$options$useCon !== void 0 && _input$options$useCon.enabled && (_Object$keys = Object.keys(builderContext.providers)) !== null && _Object$keys !== void 0 && _Object$keys.length) {
33
+ write(input.outPath, "contractContextBase.ts", _helpers.contractContextBase);
34
+ write(input.outPath, "contracts-context.tsx", _helpers.contractsContextTSX);
35
+ }
36
+ };
37
+
38
+ exports.createHelpers = createHelpers;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.contractContextBase = void 0;
7
+ var contractContextBase = "\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nexport interface IContractConstructor {\n address: string | undefined;\n cosmWasmClient: CosmWasmClient | undefined;\n signingCosmWasmClient: SigningCosmWasmClient | undefined;\n}\n\nexport const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';\n\nexport const NO_COSMWASW_CLIENT_ERROR_MESSAGE = 'cosmWasmClient not connected';\n\nexport const NO_ADDRESS_ERROR_MESSAGE = \"address doesn't exist\";\n\nexport const NO_SIGNING_CLIENT_ERROR_MESSAGE =\n 'Signing client is not generated. Please check ts-codegen config';\n\nexport const NO_QUERY_CLIENT_ERROR_MESSAGE =\n 'Query client is not generated. Please check ts-codegen config';\n\nexport const NO_MESSAGE_COMPOSER_ERROR_MESSAGE =\n 'Message composer client is not generated. Please check ts-codegen config';\n\n/**\n * a placeholder for non-generated classes\n */\nexport interface IEmptyClient {}\n\nexport interface ISigningClientProvider<T> {\n getSigningClient(contractAddr: string): T;\n}\n\nexport interface IQueryClientProvider<T> {\n getQueryClient(contractAddr: string): T;\n}\n\nexport interface IMessageComposerProvider<T> {\n getMessageComposer(contractAddr: string): T;\n}\n\nexport class ContractBase<\n TSign = IEmptyClient,\n TQuery = IEmptyClient,\n TMsgComposer = IEmptyClient\n> {\n constructor(\n protected address: string | undefined,\n protected cosmWasmClient: CosmWasmClient | undefined,\n protected signingCosmWasmClient: SigningCosmWasmClient | undefined,\n private TSign?: new (\n client: SigningCosmWasmClient,\n sender: string,\n contractAddress: string\n ) => TSign,\n private TQuery?: new (\n client: CosmWasmClient,\n contractAddress: string\n ) => TQuery,\n private TMsgComposer?: new (\n sender: string,\n contractAddress: string\n ) => TMsgComposer\n ) {}\n\n public getSigningClient(contractAddr: string): TSign {\n if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TSign) throw new Error(NO_SIGNING_CLIENT_ERROR_MESSAGE);\n return new this.TSign(\n this.signingCosmWasmClient,\n this.address,\n contractAddr\n );\n }\n\n public getQueryClient(contractAddr: string): TQuery {\n if (!this.cosmWasmClient) throw new Error(NO_COSMWASW_CLIENT_ERROR_MESSAGE);\n if (!this.TQuery) throw new Error(NO_QUERY_CLIENT_ERROR_MESSAGE);\n return new this.TQuery(this.cosmWasmClient, contractAddr);\n }\n\n public getMessageComposer(contractAddr: string): TMsgComposer {\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TMsgComposer) throw new Error(NO_MESSAGE_COMPOSER_ERROR_MESSAGE);\n return new this.TMsgComposer(this.address, contractAddr);\n }\n}\n";
8
+ exports.contractContextBase = contractContextBase;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.contractsContextTSX = void 0;
7
+ var contractsContextTSX = "\nimport React, { useEffect, useMemo, useRef, useState, useContext } from 'react';\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nimport { IContractsContext, getProviders } from './contractContextProviders';\n\ninterface ContractsConfig {\n address: string | undefined;\n getCosmWasmClient: () => Promise<CosmWasmClient>;\n getSigningCosmWasmClient: () => Promise<SigningCosmWasmClient>;\n}\n\nconst ContractsContext = React.createContext<IContractsContext | null>(null);\n\nexport const ContractsProvider = ({\n children,\n contractsConfig,\n}: {\n children: React.ReactNode;\n contractsConfig: ContractsConfig;\n}) => {\n const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient>();\n const [signingCosmWasmClient, setSigningCosmWasmClient] =\n useState<SigningCosmWasmClient>();\n\n const { address, getCosmWasmClient, getSigningCosmWasmClient } =\n contractsConfig;\n\n const prevAddressRef = useRef<string | undefined>(address);\n\n const contracts: IContractsContext = useMemo(() => {\n return getProviders(address, cosmWasmClient, signingCosmWasmClient);\n }, [address, cosmWasmClient, signingCosmWasmClient]);\n\n useEffect(() => {\n const connectSigningCwClient = async () => {\n if (address && prevAddressRef.current !== address) {\n const signingCosmWasmClient = await getSigningCosmWasmClient();\n setSigningCosmWasmClient(signingCosmWasmClient);\n } else if (!address) {\n setSigningCosmWasmClient(undefined);\n }\n prevAddressRef.current = address;\n };\n connectSigningCwClient();\n }, [address, getSigningCosmWasmClient]);\n\n useEffect(() => {\n const connectCosmWasmClient = async () => {\n const cosmWasmClient = await getCosmWasmClient();\n setCosmWasmClient(cosmWasmClient);\n };\n connectCosmWasmClient();\n }, [getCosmWasmClient]);\n\n return (\n <ContractsContext.Provider value={contracts}>\n {children}\n </ContractsContext.Provider>\n );\n};\n\nexport const useContracts = () => {\n const contracts = useContext(ContractsContext);\n if (contracts === null) {\n throw new Error('useContracts must be used within a ContractsProvider');\n }\n return contracts;\n};\n";
8
+ exports.contractsContextTSX = contractsContextTSX;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _contractContextBase = require("./contractContextBase");
8
+
9
+ Object.keys(_contractContextBase).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _contractContextBase[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _contractContextBase[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _contractsContextTSX = require("./contractsContextTSX");
21
+
22
+ Object.keys(_contractsContextTSX).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _contractsContextTSX[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _contractsContextTSX[key];
29
+ }
30
+ });
31
+ });
@@ -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.ClientPlugin = void 0;
10
+ exports.TYPE = exports.ClientPlugin = void 0;
11
11
 
12
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
13
 
@@ -39,6 +39,9 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
39
39
 
40
40
  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; } }
41
41
 
42
+ var TYPE = "client";
43
+ exports.TYPE = TYPE;
44
+
42
45
  var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
43
46
  (0, _inherits2["default"])(ClientPlugin, _BuilderPluginBase);
44
47
 
@@ -52,7 +55,7 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
52
55
  (0, _createClass2["default"])(ClientPlugin, [{
53
56
  key: "initContext",
54
57
  value: function initContext(contract, options) {
55
- return new w.RenderContext(contract, options);
58
+ return new w.RenderContext(contract, options, this.builder.builderContext);
56
59
  }
57
60
  }, {
58
61
  key: "doRender",
@@ -74,8 +77,8 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
74
77
 
75
78
  case 3:
76
79
  schemas = context.contract.schemas;
77
- localname = (0, _case.pascal)(name) + '.client.ts';
78
- TypesFile = (0, _case.pascal)(name) + '.types';
80
+ localname = (0, _case.pascal)(name) + ".client.ts";
81
+ TypesFile = (0, _case.pascal)(name) + ".types";
79
82
  QueryMsg = (0, _utils.findQueryMsg)(schemas);
80
83
  ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
81
84
  _context.next = 10;
@@ -95,6 +98,7 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
95
98
  ReadOnlyInstance = (0, _case.pascal)("".concat(name, "ReadOnlyInterface"));
96
99
  body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
97
100
  body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
101
+ context.addProviderInfo(name, w.PROVIDER_TYPES.QUERY_CLIENT_TYPE, QueryClient, localname);
98
102
  } // execute messages
99
103
 
100
104
 
@@ -106,16 +110,17 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
106
110
  Instance = (0, _case.pascal)("".concat(name, "Interface"));
107
111
  body.push(w.createExecuteInterface(context, Instance, this.option.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
108
112
  body.push(w.createExecuteClass(context, Client, Instance, this.option.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
113
+ context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
109
114
  }
110
115
  }
111
116
 
112
- if (typeHash.hasOwnProperty('Coin')) {
117
+ if (typeHash.hasOwnProperty("Coin")) {
113
118
  // @ts-ignore
114
119
  delete context.utils.Coin;
115
120
  }
116
121
 
117
122
  return _context.abrupt("return", [{
118
- type: 'client',
123
+ type: TYPE,
119
124
  localname: localname,
120
125
  body: body
121
126
  }]);
@@ -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.MessageComposerPlugin = void 0;
10
+ exports.TYPE = exports.MessageComposerPlugin = void 0;
11
11
 
12
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
13
 
@@ -39,6 +39,9 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
39
39
 
40
40
  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; } }
41
41
 
42
+ var TYPE = "message-composer";
43
+ exports.TYPE = TYPE;
44
+
42
45
  var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
43
46
  (0, _inherits2["default"])(MessageComposerPlugin, _BuilderPluginBase);
44
47
 
@@ -52,7 +55,7 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
52
55
  (0, _createClass2["default"])(MessageComposerPlugin, [{
53
56
  key: "initContext",
54
57
  value: function initContext(contract, options) {
55
- return new w.RenderContext(contract, options);
58
+ return new w.RenderContext(contract, options, this.builder.builderContext);
56
59
  }
57
60
  }, {
58
61
  key: "doRender",
@@ -74,8 +77,8 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
74
77
 
75
78
  case 3:
76
79
  schemas = context.contract.schemas;
77
- localname = (0, _case.pascal)(name) + '.message-composer.ts';
78
- TypesFile = (0, _case.pascal)(name) + '.types';
80
+ localname = (0, _case.pascal)(name) + ".message-composer.ts";
81
+ TypesFile = (0, _case.pascal)(name) + ".types";
79
82
  ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
80
83
  _context.next = 9;
81
84
  return (0, _utils.findAndParseTypes)(schemas);
@@ -93,16 +96,17 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
93
96
  Interface = (0, _case.pascal)("".concat(name, "Message"));
94
97
  body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
95
98
  body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
99
+ context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
96
100
  }
97
101
  }
98
102
 
99
- if (typeHash.hasOwnProperty('Coin')) {
103
+ if (typeHash.hasOwnProperty("Coin")) {
100
104
  // @ts-ignore
101
105
  delete context.utils.Coin;
102
106
  }
103
107
 
104
108
  return _context.abrupt("return", [{
105
- type: 'message-composer',
109
+ type: TYPE,
106
110
  localname: localname,
107
111
  body: body
108
112
  }]);
@@ -52,7 +52,7 @@ var MsgBuilderPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
52
52
  (0, _createClass2["default"])(MsgBuilderPlugin, [{
53
53
  key: "initContext",
54
54
  value: function initContext(contract, options) {
55
- return new w.RenderContext(contract, options);
55
+ return new w.RenderContext(contract, options, this.builder.builderContext);
56
56
  }
57
57
  }, {
58
58
  key: "doRender",
@@ -41,14 +41,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
41
41
  * BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
42
42
  */
43
43
  var BuilderPluginBase = /*#__PURE__*/function () {
44
- function BuilderPluginBase(opt) {
44
+ function BuilderPluginBase(opt, builder) {
45
45
  (0, _classCallCheck2["default"])(this, BuilderPluginBase);
46
+ (0, _defineProperty2["default"])(this, "builder", void 0);
46
47
  (0, _defineProperty2["default"])(this, "option", void 0);
47
48
  (0, _defineProperty2["default"])(this, "utils", void 0);
48
49
  this.option = opt;
50
+ this.builder = builder;
49
51
  }
50
52
 
51
53
  (0, _createClass2["default"])(BuilderPluginBase, [{
54
+ key: "setBuilder",
55
+ value: function setBuilder(builder) {
56
+ this.builder = builder;
57
+ }
58
+ }, {
52
59
  key: "render",
53
60
  value: function () {
54
61
  var _render = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, contractInfo, outPath) {
@@ -85,7 +92,7 @@ var BuilderPluginBase = /*#__PURE__*/function () {
85
92
 
86
93
  case 9:
87
94
  return _context.abrupt("return", results.map(function (result) {
88
- var imports = context.getImports(_this.utils);
95
+ var imports = context.getImports(_this.utils, result.localname);
89
96
  var code = _header.header + (0, _generator["default"])(t.program([].concat((0, _toConsumableArray2["default"])(imports), (0, _toConsumableArray2["default"])(result.body)))).code;
90
97
  (0, _mkdirp.sync)(outPath);
91
98
  var filename = (0, _path.join)(outPath, result.localname);
@@ -0,0 +1,146 @@
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.ContractsProviderBundlePlugin = void 0;
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
+
18
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
+
20
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
+
22
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
+
24
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
+
26
+ var _case = require("case");
27
+
28
+ var w = _interopRequireWildcard(require("wasm-ast-types"));
29
+
30
+ var _pluginBase = require("./plugin-base");
31
+
32
+ var _provider = require("./provider");
33
+
34
+ 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); }
35
+
36
+ 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; }
37
+
38
+ 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); }; }
39
+
40
+ 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; } }
41
+
42
+ var ContractsProviderBundlePlugin = /*#__PURE__*/function (_BuilderPluginBase) {
43
+ (0, _inherits2["default"])(ContractsProviderBundlePlugin, _BuilderPluginBase);
44
+
45
+ var _super = _createSuper(ContractsProviderBundlePlugin);
46
+
47
+ function ContractsProviderBundlePlugin(opt) {
48
+ var _this;
49
+
50
+ (0, _classCallCheck2["default"])(this, ContractsProviderBundlePlugin);
51
+ _this = _super.call(this, opt);
52
+ _this.utils = {
53
+ CosmWasmClient: "@cosmjs/cosmwasm-stargate",
54
+ SigningCosmWasmClient: "@cosmjs/cosmwasm-stargate",
55
+ IQueryClientProvider: "__contractContextBase__",
56
+ ISigningClientProvider: "__contractContextBase__",
57
+ IMessageComposerProvider: "__contractContextBase__"
58
+ };
59
+ return _this;
60
+ }
61
+
62
+ (0, _createClass2["default"])(ContractsProviderBundlePlugin, [{
63
+ key: "initContext",
64
+ value: function initContext(contract, options) {
65
+ return new w.RenderContext(contract, options, this.builder.builderContext);
66
+ }
67
+ }, {
68
+ key: "doRender",
69
+ value: function () {
70
+ var _doRender = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, context) {
71
+ var _this$option, _this$option$useContr, _Object$keys;
72
+
73
+ var providerInfos, localname, body, _name, providerInfo, key, info;
74
+
75
+ return _regenerator["default"].wrap(function _callee$(_context) {
76
+ while (1) {
77
+ switch (_context.prev = _context.next) {
78
+ case 0:
79
+ if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContracts) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
80
+ _context.next = 2;
81
+ break;
82
+ }
83
+
84
+ return _context.abrupt("return");
85
+
86
+ case 2:
87
+ providerInfos = context.getProviderInfos();
88
+
89
+ if ((_Object$keys = Object.keys(providerInfos)) !== null && _Object$keys !== void 0 && _Object$keys.length) {
90
+ _context.next = 5;
91
+ break;
92
+ }
93
+
94
+ return _context.abrupt("return");
95
+
96
+ case 5:
97
+ localname = "contractContextProviders.ts";
98
+ body = [];
99
+ context.addUtil("CosmWasmClient");
100
+ context.addUtil("SigningCosmWasmClient");
101
+ context.addUtil("IQueryClientProvider");
102
+ context.addUtil("ISigningClientProvider");
103
+ context.addUtil("IMessageComposerProvider");
104
+
105
+ for (_name in providerInfos) {
106
+ if (Object.prototype.hasOwnProperty.call(providerInfos, _name)) {
107
+ providerInfo = providerInfos[_name];
108
+
109
+ for (key in providerInfo) {
110
+ if (Object.prototype.hasOwnProperty.call(providerInfo, key)) {
111
+ info = providerInfo[key];
112
+ body.push(w.importStmt([info.classname], "./".concat(info.basename)));
113
+ }
114
+ }
115
+
116
+ body.push(w.importStmt([(0, _case.pascal)(_name)], "./".concat((0, _provider.GetLocalBaseNameByContractName)(_name))));
117
+ }
118
+ }
119
+
120
+ body.push(w.createIContractsContext(providerInfos));
121
+ body.push(w.createGettingProviders(providerInfos));
122
+ return _context.abrupt("return", [{
123
+ type: "plugin",
124
+ localname: localname,
125
+ body: body
126
+ }]);
127
+
128
+ case 16:
129
+ case "end":
130
+ return _context.stop();
131
+ }
132
+ }
133
+ }, _callee, this);
134
+ }));
135
+
136
+ function doRender(_x, _x2) {
137
+ return _doRender.apply(this, arguments);
138
+ }
139
+
140
+ return doRender;
141
+ }()
142
+ }]);
143
+ return ContractsProviderBundlePlugin;
144
+ }(_pluginBase.BuilderPluginBase);
145
+
146
+ exports.ContractsProviderBundlePlugin = ContractsProviderBundlePlugin;