@cosmwasm/ts-codegen 1.9.0 → 1.11.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.
- package/README.md +1 -0
- package/builder/builder.d.ts +1 -1
- package/builder/builder.js +12 -12
- package/cli.d.ts +1 -0
- package/cli.js +2 -2
- package/commands/create-boilerplate.d.ts +1 -0
- package/commands/create-boilerplate.js +1 -1
- package/commands/generate.d.ts +1 -0
- package/commands/generate.js +1 -2
- package/commands/install.d.ts +1 -0
- package/commands/install.js +5 -5
- package/esm/builder/builder.js +19 -19
- package/esm/bundler/bundler.js +1 -1
- package/esm/cli.js +2 -2
- package/esm/commands/create-boilerplate.js +1 -1
- package/esm/commands/generate.js +1 -2
- package/esm/commands/install.js +5 -5
- package/esm/file.js +2 -2
- package/esm/helpers/create-helpers.js +9 -9
- package/esm/index.js +1 -1
- package/esm/plugins/client.js +9 -9
- package/esm/plugins/index.js +7 -7
- package/esm/plugins/message-builder.js +2 -2
- package/esm/plugins/message-composer.js +9 -9
- package/esm/plugins/plugin-base.js +9 -9
- package/esm/plugins/provider-bundle.js +20 -20
- package/esm/plugins/provider.js +12 -12
- package/esm/plugins/react-query.js +2 -2
- package/esm/plugins/recoil.js +2 -2
- package/esm/plugins/types.js +3 -3
- package/esm/ts-codegen.js +1 -1
- package/esm/utils/clean.js +3 -3
- package/esm/utils/cleanse.js +7 -7
- package/esm/utils/files.js +15 -15
- package/esm/utils/header.js +1 -1
- package/esm/utils/package.js +2 -2
- package/esm/utils/parse.js +1 -1
- package/esm/utils/prompt.js +4 -4
- package/esm/utils/schemas.js +6 -3
- package/file.js +2 -2
- package/helpers/create-helpers.d.ts +2 -1
- package/helpers/create-helpers.js +6 -6
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +6 -5
- package/plugins/client.d.ts +3 -3
- package/plugins/client.js +6 -6
- package/plugins/index.d.ts +7 -7
- package/plugins/index.js +3 -3
- package/plugins/message-builder.d.ts +1 -1
- package/plugins/message-builder.js +2 -2
- package/plugins/message-composer.d.ts +3 -3
- package/plugins/message-composer.js +6 -6
- package/plugins/plugin-base.d.ts +4 -4
- package/plugins/plugin-base.js +6 -6
- package/plugins/provider-bundle.d.ts +3 -3
- package/plugins/provider-bundle.js +16 -16
- package/plugins/provider.d.ts +3 -3
- package/plugins/provider.js +9 -9
- package/plugins/react-query.d.ts +1 -1
- package/plugins/react-query.js +2 -2
- package/plugins/recoil.d.ts +1 -1
- package/plugins/recoil.js +2 -2
- package/plugins/types.js +2 -2
- package/ts-codegen.js +1 -1
- package/utils/clean.js +3 -3
- package/utils/cleanse.js +6 -6
- package/utils/contracts.d.ts +1 -0
- package/utils/files.d.ts +1 -1
- package/utils/files.js +11 -11
- package/utils/package.js +1 -1
- package/utils/parse.js +1 -1
- package/utils/prompt.d.ts +2 -2
- package/utils/prompt.js +4 -4
- package/utils/schemas.d.ts +1 -1
- package/utils/schemas.js +6 -3
package/README.md
CHANGED
@@ -132,6 +132,7 @@ The `client` plugin will generate TS client classes for your contracts. This opt
|
|
132
132
|
| `client.enabled` | generate TS client classes for your contracts |
|
133
133
|
| `client.execExtendsQuery` | execute should extend query message clients |
|
134
134
|
| `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
|
135
|
+
| `client.useDeclareKeyword` | use declare keyword for inherited class fields |
|
135
136
|
|
136
137
|
|
137
138
|
### React Query
|
package/builder/builder.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { BuilderContext, RenderOptions } from '@cosmwasm/ts-codegen-ast';
|
2
2
|
import { IBuilderPlugin } from '../plugins';
|
3
3
|
export interface TSBuilderInput {
|
4
4
|
contracts: Array<ContractFile | string>;
|
package/builder/builder.js
CHANGED
@@ -27,28 +27,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
29
|
exports.TSBuilder = void 0;
|
30
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
31
|
+
const t = __importStar(require("@babel/types"));
|
30
32
|
const ts_codegen_ast_1 = require("@cosmwasm/ts-codegen-ast");
|
31
|
-
const
|
32
|
-
const
|
33
|
+
const case_1 = require("case");
|
34
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
33
35
|
const fs_1 = require("fs");
|
34
36
|
const mkdirp_1 = require("mkdirp");
|
37
|
+
const path_1 = require("path");
|
35
38
|
const path_2 = require("path");
|
36
|
-
const utils_1 = require("../utils");
|
37
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
38
|
-
const case_1 = require("case");
|
39
39
|
const bundler_1 = require("../bundler");
|
40
|
-
const
|
41
|
-
const
|
42
|
-
const react_query_1 = require("../plugins/react-query");
|
43
|
-
const recoil_1 = require("../plugins/recoil");
|
40
|
+
const create_helpers_1 = require("../helpers/create-helpers");
|
41
|
+
const client_1 = require("../plugins/client");
|
44
42
|
const message_builder_1 = require("../plugins/message-builder");
|
45
43
|
const message_composer_1 = require("../plugins/message-composer");
|
46
|
-
const client_1 = require("../plugins/client");
|
47
|
-
const types_1 = require("../plugins/types");
|
48
44
|
const provider_1 = require("../plugins/provider");
|
49
|
-
const create_helpers_1 = require("../helpers/create-helpers");
|
50
45
|
const provider_bundle_1 = require("../plugins/provider-bundle");
|
46
|
+
const react_query_1 = require("../plugins/react-query");
|
47
|
+
const recoil_1 = require("../plugins/recoil");
|
48
|
+
const types_1 = require("../plugins/types");
|
49
|
+
const utils_1 = require("../utils");
|
51
50
|
const contracts_1 = require("../utils/contracts");
|
51
|
+
const header_1 = require("../utils/header");
|
52
52
|
const defaultOpts = {
|
53
53
|
bundle: {
|
54
54
|
enabled: true,
|
package/cli.d.ts
CHANGED
package/cli.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.cli = void 0;
|
4
|
-
const prompt_1 = require("./utils/prompt");
|
5
4
|
const cmds_1 = require("./cmds");
|
5
|
+
const prompt_1 = require("./utils/prompt");
|
6
6
|
const question = [
|
7
7
|
{
|
8
8
|
_: true,
|
@@ -13,7 +13,7 @@ const question = [
|
|
13
13
|
}
|
14
14
|
];
|
15
15
|
const cli = async (argv) => {
|
16
|
-
|
16
|
+
let { cmd } = await (0, prompt_1.prompt)(question, argv);
|
17
17
|
if (typeof cmds_1.Commands[cmd] === 'function') {
|
18
18
|
await cmds_1.Commands[cmd](argv);
|
19
19
|
}
|
@@ -26,9 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
const dargs_1 = __importDefault(require("dargs"));
|
29
30
|
const shell = __importStar(require("shelljs"));
|
30
31
|
const prompt_1 = require("../utils/prompt");
|
31
|
-
const dargs_1 = __importDefault(require("dargs"));
|
32
32
|
const glob = require('glob').sync;
|
33
33
|
const fs = require('fs');
|
34
34
|
const path = require('path');
|
package/commands/generate.d.ts
CHANGED
package/commands/generate.js
CHANGED
@@ -3,9 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
// @ts-nocheck
|
7
|
-
const prompt_1 = require("../utils/prompt");
|
8
6
|
const index_1 = __importDefault(require("../index"));
|
7
|
+
const prompt_1 = require("../utils/prompt");
|
9
8
|
exports.default = async (argv) => {
|
10
9
|
const questions = [
|
11
10
|
{
|
package/commands/install.d.ts
CHANGED
package/commands/install.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const
|
4
|
-
const mkdirp_1 = require("mkdirp");
|
3
|
+
const fs_1 = require("fs");
|
5
4
|
const glob_1 = require("glob");
|
5
|
+
const mkdirp_1 = require("mkdirp");
|
6
|
+
const os_1 = require("os");
|
7
|
+
const parse_package_name_1 = require("parse-package-name");
|
8
|
+
const path_1 = require("path");
|
6
9
|
const rimraf_1 = require("rimraf");
|
7
10
|
const shelljs_1 = require("shelljs");
|
8
11
|
const prompt_1 = require("../utils/prompt");
|
9
|
-
const parse_package_name_1 = require("parse-package-name");
|
10
|
-
const os_1 = require("os");
|
11
|
-
const fs_1 = require("fs");
|
12
12
|
const TMPDIR = (0, os_1.tmpdir)();
|
13
13
|
const rnd = () => Math.random().toString(36).substring(2, 15) +
|
14
14
|
Math.random().toString(36).substring(2, 15);
|
package/esm/builder/builder.js
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
1
|
+
import generate from '@babel/generator';
|
2
|
+
import * as t from '@babel/types';
|
3
|
+
import { BuilderContext, defaultOptions } from '@cosmwasm/ts-codegen-ast';
|
4
|
+
import { pascal } from 'case';
|
5
|
+
import deepmerge from 'deepmerge';
|
4
6
|
import { writeFileSync } from 'fs';
|
5
|
-
import { sync as mkdirp } from
|
7
|
+
import { sync as mkdirp } from 'mkdirp';
|
8
|
+
import { join } from 'path';
|
6
9
|
import { basename } from 'path';
|
10
|
+
import { createFileBundle, recursiveModuleBundle } from '../bundler';
|
11
|
+
import { createHelpers } from '../helpers/create-helpers';
|
12
|
+
import { ClientPlugin } from '../plugins/client';
|
13
|
+
import { MessageBuilderPlugin } from '../plugins/message-builder';
|
14
|
+
import { MessageComposerPlugin } from '../plugins/message-composer';
|
15
|
+
import { ContractsContextProviderPlugin } from '../plugins/provider';
|
16
|
+
import { ContractsProviderBundlePlugin } from '../plugins/provider-bundle';
|
17
|
+
import { ReactQueryPlugin } from '../plugins/react-query';
|
18
|
+
import { RecoilPlugin } from '../plugins/recoil';
|
19
|
+
import { TypesPlugin } from '../plugins/types';
|
7
20
|
import { readSchemas } from '../utils';
|
8
|
-
import
|
9
|
-
import {
|
10
|
-
import { createFileBundle, recursiveModuleBundle } from "../bundler";
|
11
|
-
import generate from '@babel/generator';
|
12
|
-
import * as t from '@babel/types';
|
13
|
-
import { ReactQueryPlugin } from "../plugins/react-query";
|
14
|
-
import { RecoilPlugin } from "../plugins/recoil";
|
15
|
-
import { MessageBuilderPlugin } from "../plugins/message-builder";
|
16
|
-
import { MessageComposerPlugin } from "../plugins/message-composer";
|
17
|
-
import { ClientPlugin } from "../plugins/client";
|
18
|
-
import { TypesPlugin } from "../plugins/types";
|
19
|
-
import { ContractsContextProviderPlugin } from "../plugins/provider";
|
20
|
-
import { createHelpers } from "../helpers/create-helpers";
|
21
|
-
import { ContractsProviderBundlePlugin } from "../plugins/provider-bundle";
|
22
|
-
import { createDefaultContractInfo } from "../utils/contracts";
|
21
|
+
import { createDefaultContractInfo } from '../utils/contracts';
|
22
|
+
import { header } from '../utils/header';
|
23
23
|
const defaultOpts = {
|
24
24
|
bundle: {
|
25
25
|
enabled: true,
|
package/esm/bundler/bundler.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import nested from 'nested-obj';
|
3
|
-
import {
|
3
|
+
import { dirname, extname, relative } from 'path';
|
4
4
|
export const recursiveModuleBundle = (obj) => {
|
5
5
|
return Object.keys(obj).map(key => {
|
6
6
|
const value = obj[key];
|
package/esm/cli.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { prompt } from './utils/prompt';
|
2
1
|
import { Commands as commands } from './cmds';
|
2
|
+
import { prompt } from './utils/prompt';
|
3
3
|
const question = [
|
4
4
|
{
|
5
5
|
_: true,
|
@@ -10,7 +10,7 @@ const question = [
|
|
10
10
|
}
|
11
11
|
];
|
12
12
|
export const cli = async (argv) => {
|
13
|
-
|
13
|
+
let { cmd } = await prompt(question, argv);
|
14
14
|
if (typeof commands[cmd] === 'function') {
|
15
15
|
await commands[cmd](argv);
|
16
16
|
}
|
package/esm/commands/generate.js
CHANGED
package/esm/commands/install.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { sync as mkdirp } from 'mkdirp';
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
3
2
|
import { sync as glob } from 'glob';
|
3
|
+
import { sync as mkdirp } from 'mkdirp';
|
4
|
+
import { tmpdir } from 'os';
|
5
|
+
import { parse } from 'parse-package-name';
|
6
|
+
import { basename, dirname, extname, join, resolve } from 'path';
|
4
7
|
import { sync as rimraf } from 'rimraf';
|
5
8
|
import { exec } from 'shelljs';
|
6
9
|
import { prompt } from '../utils/prompt';
|
7
|
-
import { parse } from 'parse-package-name';
|
8
|
-
import { tmpdir } from 'os';
|
9
|
-
import { readFileSync, writeFileSync } from 'fs';
|
10
10
|
const TMPDIR = tmpdir();
|
11
11
|
const rnd = () => Math.random().toString(36).substring(2, 15) +
|
12
12
|
Math.random().toString(36).substring(2, 15);
|
package/esm/file.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { prompt } from './utils/prompt';
|
3
|
-
import { cli } from './cli';
|
4
2
|
import { readFileSync } from 'fs';
|
3
|
+
import { cli } from './cli';
|
4
|
+
import { prompt } from './utils/prompt';
|
5
5
|
const argv = require('minimist')(process.argv.slice(2));
|
6
6
|
const question = [
|
7
7
|
{
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { header } from
|
1
|
+
import { sync as mkdirp } from 'mkdirp';
|
2
|
+
import { basename, dirname, extname, join } from 'path';
|
3
|
+
import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from '../helpers';
|
4
|
+
import { writeContentToFile } from '../utils/files';
|
5
|
+
import { header } from '../utils/header';
|
6
6
|
const write = (outPath, file, content, varname) => {
|
7
7
|
const outFile = join(outPath, file);
|
8
8
|
mkdirp(dirname(outFile));
|
9
9
|
writeContentToFile(outPath, header + content, outFile);
|
10
10
|
return {
|
11
|
-
type:
|
12
|
-
pluginType:
|
11
|
+
type: 'plugin',
|
12
|
+
pluginType: 'helper',
|
13
13
|
contract: varname ?? basename(file, extname(file)),
|
14
14
|
localname: file,
|
15
15
|
filename: outFile,
|
@@ -20,10 +20,10 @@ export const createHelpers = (input, builderContext) => {
|
|
20
20
|
if (input.options?.useContractsHook?.enabled &&
|
21
21
|
Object.keys(builderContext.providers)?.length) {
|
22
22
|
const useShorthandCtor = input.options?.useShorthandCtor;
|
23
|
-
files.push(write(input.outPath,
|
23
|
+
files.push(write(input.outPath, 'contractContextBase.ts', useShorthandCtor
|
24
24
|
? contractContextBaseShortHandCtor
|
25
25
|
: contractContextBase));
|
26
|
-
files.push(write(input.outPath,
|
26
|
+
files.push(write(input.outPath, 'contracts-context.tsx', contractsContextTSX, 'contractsContext'));
|
27
27
|
}
|
28
28
|
return files;
|
29
29
|
};
|
package/esm/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { TSBuilder } from './builder';
|
2
|
-
export * from './utils';
|
3
2
|
export * from './builder';
|
4
3
|
export * from './bundler';
|
5
4
|
export * from './plugins';
|
5
|
+
export * from './utils';
|
6
6
|
export default async (input) => {
|
7
7
|
const builder = new TSBuilder(input);
|
8
8
|
await builder.build();
|
package/esm/plugins/client.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { BuilderPluginBase } from
|
1
|
+
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { getMessageProperties, RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
5
|
+
import { BuilderPluginBase } from './plugin-base';
|
6
6
|
export class ClientPlugin extends BuilderPluginBase {
|
7
7
|
initContext(contract, options) {
|
8
8
|
return new RenderContext(contract, options, this.builder?.builderContext);
|
@@ -13,8 +13,8 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
13
13
|
return;
|
14
14
|
}
|
15
15
|
const { schemas } = context.contract;
|
16
|
-
const localname = pascal(name) +
|
17
|
-
const TypesFile = pascal(name) +
|
16
|
+
const localname = pascal(name) + '.client.ts';
|
17
|
+
const TypesFile = pascal(name) + '.types';
|
18
18
|
const QueryMsg = findQueryMsg(schemas);
|
19
19
|
const ExecuteMsg = findExecuteMsg(schemas);
|
20
20
|
const typeHash = await findAndParseTypes(schemas);
|
@@ -43,13 +43,13 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
43
43
|
context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
|
44
44
|
}
|
45
45
|
}
|
46
|
-
if (typeHash.hasOwnProperty(
|
46
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
47
47
|
// @ts-ignore
|
48
48
|
delete context.utils.Coin;
|
49
49
|
}
|
50
50
|
return [
|
51
51
|
{
|
52
|
-
type:
|
52
|
+
type: 'client',
|
53
53
|
localname,
|
54
54
|
body,
|
55
55
|
},
|
package/esm/plugins/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
6
|
-
export * from
|
7
|
-
export * from
|
1
|
+
export * from './client';
|
2
|
+
export * from './message-builder';
|
3
|
+
export * from './message-composer';
|
4
|
+
export * from './plugin-base';
|
5
|
+
export * from './react-query';
|
6
|
+
export * from './recoil';
|
7
|
+
export * from './types';
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
3
|
-
import { findAndParseTypes, findQueryMsg, findExecuteMsg } from '../utils';
|
4
2
|
import { getMessageProperties, RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
6
6
|
export class MessageBuilderPlugin extends BuilderPluginBase {
|
7
7
|
initContext(contract, options) {
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { BuilderPluginBase } from
|
1
|
+
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { getMessageProperties, RenderContext, } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findExecuteMsg } from '../utils';
|
5
|
+
import { BuilderPluginBase } from './plugin-base';
|
6
6
|
export class MessageComposerPlugin extends BuilderPluginBase {
|
7
7
|
initContext(contract, options) {
|
8
8
|
return new RenderContext(contract, options, this.builder?.builderContext);
|
@@ -13,8 +13,8 @@ export class MessageComposerPlugin extends BuilderPluginBase {
|
|
13
13
|
return;
|
14
14
|
}
|
15
15
|
const { schemas } = context.contract;
|
16
|
-
const localname = pascal(name) +
|
17
|
-
const TypesFile = pascal(name) +
|
16
|
+
const localname = pascal(name) + '.message-composer.ts';
|
17
|
+
const TypesFile = pascal(name) + '.types';
|
18
18
|
const ExecuteMsg = findExecuteMsg(schemas);
|
19
19
|
const typeHash = await findAndParseTypes(schemas);
|
20
20
|
const body = [];
|
@@ -30,13 +30,13 @@ export class MessageComposerPlugin extends BuilderPluginBase {
|
|
30
30
|
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
31
31
|
}
|
32
32
|
}
|
33
|
-
if (typeHash.hasOwnProperty(
|
33
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
34
34
|
// @ts-ignore
|
35
35
|
delete context.utils.Coin;
|
36
36
|
}
|
37
37
|
return [
|
38
38
|
{
|
39
|
-
type:
|
39
|
+
type: 'message-composer',
|
40
40
|
localname,
|
41
41
|
body,
|
42
42
|
},
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
1
|
+
import generate from '@babel/generator';
|
2
|
+
import * as t from '@babel/types';
|
3
|
+
import { defaultOptions } from '@cosmwasm/ts-codegen-ast';
|
4
|
+
import deepmerge from 'deepmerge';
|
5
|
+
import { writeFileSync } from 'fs';
|
6
|
+
import { sync as mkdirp } from 'mkdirp';
|
7
|
+
import { join } from 'path';
|
8
|
+
import { header } from '../utils/header';
|
9
9
|
/**
|
10
10
|
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
11
11
|
*/
|
@@ -21,7 +21,7 @@ export class BuilderPluginBase {
|
|
21
21
|
constructor(opts, builder) {
|
22
22
|
this.options = opts;
|
23
23
|
this.builder = builder;
|
24
|
-
this.lifecycle =
|
24
|
+
this.lifecycle = 'main';
|
25
25
|
}
|
26
26
|
setBuilder(builder) {
|
27
27
|
this.builder = builder;
|
@@ -1,19 +1,19 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import { BuilderPluginBase } from
|
5
|
-
import { GetLocalBaseNameByContractName } from
|
1
|
+
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { BuilderPluginBase } from './plugin-base';
|
5
|
+
import { GetLocalBaseNameByContractName } from './provider';
|
6
6
|
export class ContractsProviderBundlePlugin extends BuilderPluginBase {
|
7
7
|
constructor(opt) {
|
8
8
|
super(opt);
|
9
|
-
this.lifecycle =
|
10
|
-
this.defaultContractName =
|
9
|
+
this.lifecycle = 'after';
|
10
|
+
this.defaultContractName = 'contractContextProviders';
|
11
11
|
this.utils = {
|
12
|
-
CosmWasmClient:
|
13
|
-
SigningCosmWasmClient:
|
14
|
-
IQueryClientProvider:
|
15
|
-
ISigningClientProvider:
|
16
|
-
IMessageComposerProvider:
|
12
|
+
CosmWasmClient: '@cosmjs/cosmwasm-stargate',
|
13
|
+
SigningCosmWasmClient: '@cosmjs/cosmwasm-stargate',
|
14
|
+
IQueryClientProvider: '__contractContextBase__',
|
15
|
+
ISigningClientProvider: '__contractContextBase__',
|
16
|
+
IMessageComposerProvider: '__contractContextBase__',
|
17
17
|
};
|
18
18
|
}
|
19
19
|
initContext(contract, options) {
|
@@ -27,13 +27,13 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase {
|
|
27
27
|
if (!Object.keys(providerInfos || {})?.length) {
|
28
28
|
return;
|
29
29
|
}
|
30
|
-
const localname =
|
30
|
+
const localname = 'contractContextProviders.ts';
|
31
31
|
const body = [];
|
32
|
-
context.addUtil(
|
33
|
-
context.addUtil(
|
34
|
-
context.addUtil(
|
35
|
-
context.addUtil(
|
36
|
-
context.addUtil(
|
32
|
+
context.addUtil('CosmWasmClient');
|
33
|
+
context.addUtil('SigningCosmWasmClient');
|
34
|
+
context.addUtil('IQueryClientProvider');
|
35
|
+
context.addUtil('ISigningClientProvider');
|
36
|
+
context.addUtil('IMessageComposerProvider');
|
37
37
|
for (const name in providerInfos) {
|
38
38
|
if (Object.prototype.hasOwnProperty.call(providerInfos, name)) {
|
39
39
|
const providerInfo = providerInfos[name];
|
@@ -50,8 +50,8 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase {
|
|
50
50
|
body.push(w.createGettingProviders(providerInfos));
|
51
51
|
return [
|
52
52
|
{
|
53
|
-
type:
|
54
|
-
pluginType:
|
53
|
+
type: 'plugin',
|
54
|
+
pluginType: 'contractContextProviders',
|
55
55
|
localname,
|
56
56
|
body,
|
57
57
|
},
|
package/esm/plugins/provider.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import { BuilderPluginBase } from
|
1
|
+
import * as w from '@cosmwasm/ts-codegen-ast';
|
2
|
+
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { BuilderPluginBase } from './plugin-base';
|
5
5
|
export const GetLocalNameByContractName = (name) => `${pascal(name)}.provider.ts`;
|
6
6
|
export const GetLocalBaseNameByContractName = (name) => `${pascal(name)}.provider`;
|
7
7
|
export class ContractsContextProviderPlugin extends BuilderPluginBase {
|
8
8
|
constructor(opt) {
|
9
9
|
super(opt);
|
10
10
|
this.utils = {
|
11
|
-
ContractBase:
|
12
|
-
IContractConstructor:
|
13
|
-
IEmptyClient:
|
11
|
+
ContractBase: '__contractContextBase__',
|
12
|
+
IContractConstructor: '__contractContextBase__',
|
13
|
+
IEmptyClient: '__contractContextBase__',
|
14
14
|
};
|
15
15
|
}
|
16
16
|
initContext(contract, options) {
|
@@ -24,8 +24,8 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase {
|
|
24
24
|
if (!Object.keys(providerInfo || {})?.length) {
|
25
25
|
return;
|
26
26
|
}
|
27
|
-
context.addUtil(
|
28
|
-
context.addUtil(
|
27
|
+
context.addUtil('ContractBase');
|
28
|
+
context.addUtil('IContractConstructor');
|
29
29
|
const localname = GetLocalNameByContractName(name);
|
30
30
|
let needEmptyClientType = false;
|
31
31
|
let clientFile = null;
|
@@ -58,13 +58,13 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase {
|
|
58
58
|
needEmptyClientType = true;
|
59
59
|
}
|
60
60
|
if (needEmptyClientType) {
|
61
|
-
context.addUtil(
|
61
|
+
context.addUtil('IEmptyClient');
|
62
62
|
}
|
63
63
|
body.push(w.createProvider(name, providerInfo));
|
64
64
|
return [
|
65
65
|
{
|
66
|
-
type:
|
67
|
-
pluginType:
|
66
|
+
type: 'plugin',
|
67
|
+
pluginType: 'provider',
|
68
68
|
localname,
|
69
69
|
body,
|
70
70
|
},
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
3
|
-
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
4
2
|
import { getMessageProperties, RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
6
6
|
export class ReactQueryPlugin extends BuilderPluginBase {
|
7
7
|
initContext(contract, options) {
|
package/esm/plugins/recoil.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
1
|
import * as w from '@cosmwasm/ts-codegen-ast';
|
3
|
-
import { findAndParseTypes, findQueryMsg } from '../utils';
|
4
2
|
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findQueryMsg } from '../utils';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
6
6
|
export class RecoilPlugin extends BuilderPluginBase {
|
7
7
|
utils = {
|
package/esm/plugins/types.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { clean } from '../utils/clean';
|
3
|
-
import { pascal } from 'case';
|
4
|
-
import { findExecuteMsg, findAndParseTypes } from '../utils';
|
5
2
|
import { RenderContext } from '@cosmwasm/ts-codegen-ast';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findAndParseTypes, findExecuteMsg } from '../utils';
|
5
|
+
import { clean } from '../utils/clean';
|
6
6
|
import { BuilderPluginBase } from './plugin-base';
|
7
7
|
export class TypesPlugin extends BuilderPluginBase {
|
8
8
|
initContext(contract, options) {
|