@cosmwasm/ts-codegen 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +13 -28
  2. package/builder/builder.js +11 -16
  3. package/cli.d.ts +1 -1
  4. package/commands/create-boilerplate.d.ts +1 -1
  5. package/commands/generate.d.ts +1 -1
  6. package/commands/install.d.ts +1 -1
  7. package/esm/builder/builder.js +11 -16
  8. package/esm/{generators → helpers}/create-helpers.js +1 -9
  9. package/esm/index.js +0 -6
  10. package/esm/plugins/client.js +5 -6
  11. package/esm/plugins/index.js +6 -0
  12. package/esm/plugins/message-builder.js +2 -2
  13. package/esm/plugins/message-composer.js +3 -4
  14. package/esm/plugins/plugin-base.js +23 -6
  15. package/esm/plugins/provider-bundle.js +4 -2
  16. package/esm/plugins/provider.js +2 -2
  17. package/esm/plugins/react-query.js +2 -2
  18. package/esm/plugins/recoil.js +2 -2
  19. package/esm/plugins/types.js +3 -3
  20. package/esm/utils/contracts.js +5 -0
  21. package/{generators → helpers}/create-helpers.js +2 -10
  22. package/index.d.ts +0 -6
  23. package/index.js +0 -16
  24. package/package.json +6 -5
  25. package/plugins/client.d.ts +0 -1
  26. package/plugins/client.js +6 -7
  27. package/plugins/index.d.ts +6 -0
  28. package/plugins/index.js +6 -0
  29. package/plugins/message-builder.js +2 -2
  30. package/plugins/message-composer.d.ts +0 -1
  31. package/plugins/message-composer.js +4 -5
  32. package/plugins/plugin-base.d.ts +18 -4
  33. package/plugins/plugin-base.js +23 -6
  34. package/plugins/provider-bundle.d.ts +1 -1
  35. package/plugins/provider-bundle.js +4 -2
  36. package/plugins/provider.js +2 -2
  37. package/plugins/react-query.js +2 -2
  38. package/plugins/recoil.js +2 -2
  39. package/plugins/types.js +3 -3
  40. package/utils/contracts.d.ts +2 -0
  41. package/utils/contracts.js +9 -0
  42. package/utils/schemas.d.ts +1 -1
  43. package/esm/generators/client.js +0 -67
  44. package/esm/generators/message-builder.js +0 -58
  45. package/esm/generators/message-composer.js +0 -55
  46. package/esm/generators/react-query.js +0 -76
  47. package/esm/generators/recoil.js +0 -58
  48. package/esm/generators/types.js +0 -58
  49. package/generators/client.d.ts +0 -5
  50. package/generators/client.js +0 -95
  51. package/generators/message-builder.d.ts +0 -5
  52. package/generators/message-builder.js +0 -86
  53. package/generators/message-composer.d.ts +0 -5
  54. package/generators/message-composer.js +0 -83
  55. package/generators/react-query.d.ts +0 -4
  56. package/generators/react-query.js +0 -104
  57. package/generators/recoil.d.ts +0 -4
  58. package/generators/recoil.js +0 -86
  59. package/generators/types.d.ts +0 -4
  60. package/generators/types.js +0 -86
  61. /package/{generators → helpers}/create-helpers.d.ts +0 -0
@@ -1,58 +0,0 @@
1
- import { pascal } from "case";
2
- import { header } from '../utils/header';
3
- import { join } from "path";
4
- import { sync as mkdirp } from "mkdirp";
5
- import * as t from '@babel/types';
6
- import { writeFileSync } from 'fs';
7
- import generate from "@babel/generator";
8
- import { clean } from "../utils/clean";
9
- import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
10
- import { RenderContext } from "wasm-ast-types";
11
- export default async (name, contractInfo, outPath, tsTypesOptions) => {
12
- const { schemas } = contractInfo;
13
- const context = new RenderContext(contractInfo, {
14
- types: tsTypesOptions ?? {}
15
- });
16
- const options = context.options.types;
17
- const localname = pascal(name) + '.types.ts';
18
- const ExecuteMsg = findExecuteMsg(schemas);
19
- const typeHash = await findAndParseTypes(schemas);
20
- const body = [];
21
- // TYPES
22
- Object.values(typeHash).forEach((type) => {
23
- body.push(clean(type));
24
- });
25
- // alias the ExecuteMsg (deprecated option)
26
- if (options.aliasExecuteMsg && ExecuteMsg) {
27
- body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
28
- }
29
- function addEntryPointAlias(msgName) {
30
- body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
31
- }
32
- if (options.aliasEntryPoints) {
33
- if (ExecuteMsg) {
34
- addEntryPointAlias('ExecuteMsg');
35
- }
36
- if (findQueryMsg(schemas)) {
37
- addEntryPointAlias('QueryMsg');
38
- }
39
- }
40
- const imports = context.getImports();
41
- const code = header + generate(
42
- // @ts-ignore
43
- t.program([
44
- ...imports,
45
- ...body
46
- ])).code;
47
- mkdirp(outPath);
48
- const filename = join(outPath, localname);
49
- writeFileSync(filename, code);
50
- return [
51
- {
52
- type: 'type',
53
- contract: name,
54
- localname,
55
- filename,
56
- }
57
- ];
58
- };
@@ -1,5 +0,0 @@
1
- import { ContractInfo } from "wasm-ast-types";
2
- import { TSClientOptions } from "wasm-ast-types";
3
- import { BuilderFile } from "../builder";
4
- declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, tsClientOptions?: TSClientOptions) => Promise<BuilderFile[]>;
5
- export default _default;
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const w = __importStar(require("wasm-ast-types"));
34
- const t = __importStar(require("@babel/types"));
35
- const fs_1 = require("fs");
36
- const generator_1 = __importDefault(require("@babel/generator"));
37
- const wasm_ast_types_1 = require("wasm-ast-types");
38
- const utils_1 = require("../utils");
39
- const wasm_ast_types_2 = require("wasm-ast-types");
40
- exports.default = async (name, contractInfo, outPath, tsClientOptions) => {
41
- const { schemas } = contractInfo;
42
- const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
- client: tsClientOptions ?? {}
44
- });
45
- // const options = context.options.client;
46
- const localname = (0, case_1.pascal)(name) + '.client.ts';
47
- const TypesFile = (0, case_1.pascal)(name) + '.types';
48
- const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
49
- const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
50
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
51
- let Client = null;
52
- let Instance = null;
53
- let QueryClient = null;
54
- let ReadOnlyInstance = null;
55
- const body = [];
56
- body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
57
- // query messages
58
- if (QueryMsg) {
59
- QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
60
- ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
61
- body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
62
- body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
63
- }
64
- // execute messages
65
- if (ExecuteMsg) {
66
- const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
67
- if (children.length > 0) {
68
- Client = (0, case_1.pascal)(`${name}Client`);
69
- Instance = (0, case_1.pascal)(`${name}Interface`);
70
- body.push(w.createExecuteInterface(context, Instance, context.options.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
71
- body.push(w.createExecuteClass(context, Client, Instance, context.options.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
72
- }
73
- }
74
- if (typeHash.hasOwnProperty('Coin')) {
75
- // @ts-ignore
76
- delete context.utils.Coin;
77
- }
78
- const imports = context.getImports();
79
- const code = header_1.header + (0, generator_1.default)(
80
- // @ts-ignore
81
- t.program([
82
- ...imports,
83
- ...body
84
- ])).code;
85
- (0, mkdirp_1.sync)(outPath);
86
- (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
87
- return [
88
- {
89
- type: 'client',
90
- contract: name,
91
- localname,
92
- filename: (0, path_1.join)(outPath, localname),
93
- }
94
- ];
95
- };
@@ -1,5 +0,0 @@
1
- import { ContractInfo } from "wasm-ast-types";
2
- import { MessageBuilderOptions } from 'wasm-ast-types';
3
- import { BuilderFile } from "../builder";
4
- declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, messageBuilderOptions?: MessageBuilderOptions) => Promise<BuilderFile[]>;
5
- export default _default;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const w = __importStar(require("wasm-ast-types"));
34
- const t = __importStar(require("@babel/types"));
35
- const fs_1 = require("fs");
36
- const generator_1 = __importDefault(require("@babel/generator"));
37
- const wasm_ast_types_1 = require("wasm-ast-types");
38
- const utils_1 = require("../utils");
39
- const wasm_ast_types_2 = require("wasm-ast-types");
40
- exports.default = async (name, contractInfo, outPath, messageBuilderOptions) => {
41
- const { schemas } = contractInfo;
42
- const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
- messageBuilder: messageBuilderOptions ?? {},
44
- });
45
- const localname = (0, case_1.pascal)(name) + ".message-builder.ts";
46
- const TypesFile = (0, case_1.pascal)(name) + ".types";
47
- const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
48
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
49
- const body = [];
50
- body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
51
- body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
52
- // execute messages
53
- if (ExecuteMsg) {
54
- const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
55
- if (children.length > 0) {
56
- const className = (0, case_1.pascal)(`${name}ExecuteMsgBuilder`);
57
- body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
58
- }
59
- }
60
- const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
61
- // query messages
62
- if (QueryMsg) {
63
- const children = (0, wasm_ast_types_1.getMessageProperties)(QueryMsg);
64
- if (children.length > 0) {
65
- const className = (0, case_1.pascal)(`${name}QueryMsgBuilder`);
66
- body.push(w.createMessageBuilderClass(context, className, QueryMsg));
67
- }
68
- }
69
- if (typeHash.hasOwnProperty("Coin")) {
70
- // @ts-ignore
71
- delete context.utils.Coin;
72
- }
73
- const imports = context.getImports();
74
- // @ts-ignore
75
- const code = header_1.header + (0, generator_1.default)(t.program([...imports, ...body])).code;
76
- (0, mkdirp_1.sync)(outPath);
77
- (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
78
- return [
79
- {
80
- type: "message-builder",
81
- contract: name,
82
- localname,
83
- filename: (0, path_1.join)(outPath, localname),
84
- },
85
- ];
86
- };
@@ -1,5 +0,0 @@
1
- import { ContractInfo } from "wasm-ast-types";
2
- import { MessageComposerOptions } from "wasm-ast-types";
3
- import { BuilderFile } from "../builder";
4
- declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, messageComposerOptions?: MessageComposerOptions) => Promise<BuilderFile[]>;
5
- export default _default;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const w = __importStar(require("wasm-ast-types"));
34
- const t = __importStar(require("@babel/types"));
35
- const fs_1 = require("fs");
36
- const generator_1 = __importDefault(require("@babel/generator"));
37
- const wasm_ast_types_1 = require("wasm-ast-types");
38
- const utils_1 = require("../utils");
39
- const wasm_ast_types_2 = require("wasm-ast-types");
40
- exports.default = async (name, contractInfo, outPath, messageComposerOptions) => {
41
- const { schemas } = contractInfo;
42
- const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
- messageComposer: messageComposerOptions ?? {}
44
- });
45
- // const options = context.options.messageComposer;
46
- const localname = (0, case_1.pascal)(name) + '.message-composer.ts';
47
- const TypesFile = (0, case_1.pascal)(name) + '.types';
48
- const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
49
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
50
- const body = [];
51
- body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
52
- // execute messages
53
- if (ExecuteMsg) {
54
- const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
55
- if (children.length > 0) {
56
- const TheClass = (0, case_1.pascal)(`${name}MessageComposer`);
57
- const Interface = (0, case_1.pascal)(`${name}Message`);
58
- body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
59
- body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
60
- }
61
- }
62
- if (typeHash.hasOwnProperty('Coin')) {
63
- // @ts-ignore
64
- delete context.utils.Coin;
65
- }
66
- const imports = context.getImports();
67
- const code = header_1.header + (0, generator_1.default)(
68
- // @ts-ignore
69
- t.program([
70
- ...imports,
71
- ...body
72
- ])).code;
73
- (0, mkdirp_1.sync)(outPath);
74
- (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
75
- return [
76
- {
77
- type: 'message-composer',
78
- contract: name,
79
- localname,
80
- filename: (0, path_1.join)(outPath, localname),
81
- }
82
- ];
83
- };
@@ -1,4 +0,0 @@
1
- import { ReactQueryOptions, ContractInfo } from "wasm-ast-types";
2
- import { BuilderFile } from "../builder";
3
- declare const _default: (contractName: string, contractInfo: ContractInfo, outPath: string, reactQueryOptions?: ReactQueryOptions) => Promise<BuilderFile[]>;
4
- export default _default;
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const w = __importStar(require("wasm-ast-types"));
34
- const wasm_ast_types_1 = require("wasm-ast-types");
35
- const t = __importStar(require("@babel/types"));
36
- const fs_1 = require("fs");
37
- const generator_1 = __importDefault(require("@babel/generator"));
38
- const utils_1 = require("../utils");
39
- const wasm_ast_types_2 = require("wasm-ast-types");
40
- exports.default = async (contractName, contractInfo, outPath, reactQueryOptions) => {
41
- const { schemas } = contractInfo;
42
- const context = new wasm_ast_types_1.RenderContext(contractInfo, {
43
- reactQuery: reactQueryOptions ?? {}
44
- });
45
- const options = context.options.reactQuery;
46
- const localname = (0, case_1.pascal)(`${contractName}`) + '.react-query.ts';
47
- const ContractFile = (0, case_1.pascal)(`${contractName}`) + '.client';
48
- const TypesFile = (0, case_1.pascal)(`${contractName}`) + '.types';
49
- const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
50
- const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
51
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
52
- const ExecuteClient = (0, case_1.pascal)(`${contractName}Client`);
53
- const QueryClient = (0, case_1.pascal)(`${contractName}QueryClient`);
54
- const body = [];
55
- const clientImports = [];
56
- QueryMsg && clientImports.push(QueryClient);
57
- // check that there are commands within the exec msg
58
- const shouldGenerateMutationHooks = ExecuteMsg && options?.version === 'v4' && options?.mutations && (0, wasm_ast_types_2.getMessageProperties)(ExecuteMsg).length > 0;
59
- if (shouldGenerateMutationHooks) {
60
- clientImports.push(ExecuteClient);
61
- }
62
- // general contract imports
63
- body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
64
- // client imports
65
- body.push(w.importStmt(clientImports, `./${ContractFile}`));
66
- // query messages
67
- if (QueryMsg) {
68
- [].push.apply(body, w.createReactQueryHooks({
69
- context,
70
- queryMsg: QueryMsg,
71
- contractName: contractName,
72
- QueryClient
73
- }));
74
- }
75
- if (shouldGenerateMutationHooks) {
76
- [].push.apply(body, w.createReactQueryMutationHooks({
77
- context,
78
- execMsg: ExecuteMsg,
79
- contractName: contractName,
80
- ExecuteClient
81
- }));
82
- }
83
- if (typeHash.hasOwnProperty('Coin')) {
84
- // @ts-ignore
85
- delete context.utils.Coin;
86
- }
87
- const imports = context.getImports();
88
- const code = header_1.header + (0, generator_1.default)(
89
- // @ts-ignore
90
- t.program([
91
- ...imports,
92
- ...body
93
- ])).code;
94
- (0, mkdirp_1.sync)(outPath);
95
- (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
96
- return [
97
- {
98
- type: 'react-query',
99
- contract: contractName,
100
- localname,
101
- filename: (0, path_1.join)(outPath, localname),
102
- }
103
- ];
104
- };
@@ -1,4 +0,0 @@
1
- import { ContractInfo, RecoilOptions } from "wasm-ast-types";
2
- import { BuilderFile } from "../builder";
3
- declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, recoilOptions?: RecoilOptions) => Promise<BuilderFile[]>;
4
- export default _default;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const w = __importStar(require("wasm-ast-types"));
34
- const t = __importStar(require("@babel/types"));
35
- const fs_1 = require("fs");
36
- const generator_1 = __importDefault(require("@babel/generator"));
37
- const utils_1 = require("../utils");
38
- const wasm_ast_types_1 = require("wasm-ast-types");
39
- exports.default = async (name, contractInfo, outPath, recoilOptions) => {
40
- const { schemas } = contractInfo;
41
- const context = new wasm_ast_types_1.RenderContext(contractInfo, {
42
- recoil: recoilOptions ?? {}
43
- });
44
- const options = context.options.recoil;
45
- const localname = (0, case_1.pascal)(name) + '.recoil.ts';
46
- const ContractFile = (0, case_1.pascal)(name) + '.client';
47
- const TypesFile = (0, case_1.pascal)(name) + '.types';
48
- const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
49
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
50
- let QueryClient = null;
51
- let ReadOnlyInstance = null;
52
- const body = [];
53
- body.push(w.importStmt(['cosmWasmClient'], './chain'));
54
- body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
55
- // query messages
56
- if (QueryMsg) {
57
- QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
58
- ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
59
- body.push(w.importStmt([QueryClient], `./${ContractFile}`));
60
- body.push(w.createRecoilQueryClientType());
61
- body.push(w.createRecoilQueryClient(context, name, QueryClient));
62
- const selectors = w.createRecoilSelectors(context, name, QueryClient, QueryMsg);
63
- body.push(...selectors);
64
- }
65
- if (typeHash.hasOwnProperty('Coin')) {
66
- // @ts-ignore
67
- delete context.utils.Coin;
68
- }
69
- const imports = context.getImports();
70
- const code = header_1.header + (0, generator_1.default)(
71
- // @ts-ignore
72
- t.program([
73
- ...imports,
74
- ...body
75
- ])).code;
76
- (0, mkdirp_1.sync)(outPath);
77
- (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
78
- return [
79
- {
80
- type: 'recoil',
81
- contract: name,
82
- localname,
83
- filename: (0, path_1.join)(outPath, localname),
84
- }
85
- ];
86
- };
@@ -1,4 +0,0 @@
1
- import { ContractInfo, TSTypesOptions } from "wasm-ast-types";
2
- import { BuilderFile } from "../builder";
3
- declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, tsTypesOptions?: TSTypesOptions) => Promise<BuilderFile[]>;
4
- export default _default;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const case_1 = require("case");
30
- const header_1 = require("../utils/header");
31
- const path_1 = require("path");
32
- const mkdirp_1 = require("mkdirp");
33
- const t = __importStar(require("@babel/types"));
34
- const fs_1 = require("fs");
35
- const generator_1 = __importDefault(require("@babel/generator"));
36
- const clean_1 = require("../utils/clean");
37
- const utils_1 = require("../utils");
38
- const wasm_ast_types_1 = require("wasm-ast-types");
39
- exports.default = async (name, contractInfo, outPath, tsTypesOptions) => {
40
- const { schemas } = contractInfo;
41
- const context = new wasm_ast_types_1.RenderContext(contractInfo, {
42
- types: tsTypesOptions ?? {}
43
- });
44
- const options = context.options.types;
45
- const localname = (0, case_1.pascal)(name) + '.types.ts';
46
- const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
47
- const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
48
- const body = [];
49
- // TYPES
50
- Object.values(typeHash).forEach((type) => {
51
- body.push((0, clean_1.clean)(type));
52
- });
53
- // alias the ExecuteMsg (deprecated option)
54
- if (options.aliasExecuteMsg && ExecuteMsg) {
55
- body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
56
- }
57
- function addEntryPointAlias(msgName) {
58
- body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
59
- }
60
- if (options.aliasEntryPoints) {
61
- if (ExecuteMsg) {
62
- addEntryPointAlias('ExecuteMsg');
63
- }
64
- if ((0, utils_1.findQueryMsg)(schemas)) {
65
- addEntryPointAlias('QueryMsg');
66
- }
67
- }
68
- const imports = context.getImports();
69
- const code = header_1.header + (0, generator_1.default)(
70
- // @ts-ignore
71
- t.program([
72
- ...imports,
73
- ...body
74
- ])).code;
75
- (0, mkdirp_1.sync)(outPath);
76
- const filename = (0, path_1.join)(outPath, localname);
77
- (0, fs_1.writeFileSync)(filename, code);
78
- return [
79
- {
80
- type: 'type',
81
- contract: name,
82
- localname,
83
- filename,
84
- }
85
- ];
86
- };
File without changes