wasm-ast-types 0.26.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +1 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.RenderContext = exports.RenderContextBase = exports.BuilderContext = exports.getDefinitionSchema = exports.defaultOptions = void 0;
|
7
|
+
const utils_1 = require("../utils");
|
8
|
+
const imports_1 = require("./imports");
|
9
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
10
|
+
const path_1 = require("path");
|
11
|
+
;
|
12
|
+
exports.defaultOptions = {
|
13
|
+
enabled: true,
|
14
|
+
types: {
|
15
|
+
enabled: true,
|
16
|
+
itemsUseTuples: false,
|
17
|
+
aliasExecuteMsg: false
|
18
|
+
},
|
19
|
+
client: {
|
20
|
+
enabled: true,
|
21
|
+
execExtendsQuery: true,
|
22
|
+
noImplicitOverride: false,
|
23
|
+
},
|
24
|
+
recoil: {
|
25
|
+
enabled: false
|
26
|
+
},
|
27
|
+
messageComposer: {
|
28
|
+
enabled: false
|
29
|
+
},
|
30
|
+
messageBuilder: {
|
31
|
+
enabled: false,
|
32
|
+
},
|
33
|
+
reactQuery: {
|
34
|
+
enabled: false,
|
35
|
+
optionalClient: false,
|
36
|
+
version: 'v4',
|
37
|
+
mutations: false,
|
38
|
+
camelize: true,
|
39
|
+
queryKeys: false
|
40
|
+
}
|
41
|
+
};
|
42
|
+
const getDefinitionSchema = (schemas) => {
|
43
|
+
const aggregateSchema = {
|
44
|
+
definitions: {
|
45
|
+
//
|
46
|
+
}
|
47
|
+
};
|
48
|
+
schemas.forEach(schema => {
|
49
|
+
schema.definitions = schema.definitions || {};
|
50
|
+
aggregateSchema.definitions = {
|
51
|
+
...aggregateSchema.definitions,
|
52
|
+
...schema.definitions
|
53
|
+
};
|
54
|
+
});
|
55
|
+
return aggregateSchema;
|
56
|
+
};
|
57
|
+
exports.getDefinitionSchema = getDefinitionSchema;
|
58
|
+
class BuilderContext {
|
59
|
+
providers = {};
|
60
|
+
addProviderInfo(contractName, type, classname, filename) {
|
61
|
+
if (!this.providers[contractName]) {
|
62
|
+
this.providers[contractName] = {};
|
63
|
+
}
|
64
|
+
this.providers[contractName][type] = {
|
65
|
+
classname,
|
66
|
+
filename,
|
67
|
+
basename: (0, path_1.basename)(filename, (0, path_1.extname)(filename))
|
68
|
+
};
|
69
|
+
}
|
70
|
+
getProviderInfos() {
|
71
|
+
return this.providers;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
exports.BuilderContext = BuilderContext;
|
75
|
+
/**
|
76
|
+
* context object for generating code.
|
77
|
+
* only mergeDefaultOpt needs to implementing for combine options and default options.
|
78
|
+
* @param TOpt option type
|
79
|
+
*/
|
80
|
+
class RenderContextBase {
|
81
|
+
builderContext;
|
82
|
+
contract;
|
83
|
+
utils = {};
|
84
|
+
schema;
|
85
|
+
options;
|
86
|
+
constructor(contract, options, builderContext) {
|
87
|
+
this.contract = contract;
|
88
|
+
this.schema = (0, exports.getDefinitionSchema)(contract.schemas);
|
89
|
+
this.options = this.mergeDefaultOpt(options);
|
90
|
+
this.builderContext = builderContext;
|
91
|
+
}
|
92
|
+
refLookup($ref) {
|
93
|
+
return (0, utils_1.refLookup)($ref, this.schema);
|
94
|
+
}
|
95
|
+
addUtil(util) {
|
96
|
+
this.utils[util] = true;
|
97
|
+
}
|
98
|
+
addProviderInfo(contractName, type, classname, filename) {
|
99
|
+
this.builderContext.addProviderInfo(contractName, type, classname, filename);
|
100
|
+
}
|
101
|
+
getProviderInfos() {
|
102
|
+
return this.builderContext.providers;
|
103
|
+
}
|
104
|
+
getImports(registeredUtils, filepath) {
|
105
|
+
return (0, imports_1.getImportStatements)((0, imports_1.convertUtilsToImportList)(this, Object.keys(this.utils), registeredUtils), filepath);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
exports.RenderContextBase = RenderContextBase;
|
109
|
+
class RenderContext extends RenderContextBase {
|
110
|
+
mergeDefaultOpt(options) {
|
111
|
+
return (0, deepmerge_1.default)(exports.defaultOptions, options ?? {});
|
112
|
+
}
|
113
|
+
}
|
114
|
+
exports.RenderContext = RenderContext;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as t from '@babel/types';
|
1
2
|
import { RenderContext } from './context';
|
2
3
|
export interface ImportObj {
|
3
4
|
type: 'import' | 'default' | 'namespace';
|
@@ -5,8 +6,8 @@ export interface ImportObj {
|
|
5
6
|
path: string;
|
6
7
|
importAs?: string;
|
7
8
|
}
|
8
|
-
export
|
9
|
-
export
|
9
|
+
export type GetUtilFn = (<TContext = RenderContext>(...args: any[]) => (context: TContext) => ImportObj);
|
10
|
+
export type UtilMapping = {
|
10
11
|
[key: string]: ImportObj | string | GetUtilFn;
|
11
12
|
};
|
12
13
|
export declare const UTILS: {
|
@@ -22,26 +23,26 @@ export declare const UTILS: {
|
|
22
23
|
useQuery: (context: RenderContext) => {
|
23
24
|
type: string;
|
24
25
|
path: string;
|
25
|
-
name:
|
26
|
+
name: string;
|
26
27
|
};
|
27
28
|
UseQueryOptions: (context: RenderContext) => {
|
28
29
|
type: string;
|
29
30
|
path: string;
|
30
|
-
name:
|
31
|
+
name: string;
|
31
32
|
};
|
32
33
|
useMutation: (context: RenderContext) => {
|
33
34
|
type: string;
|
34
35
|
path: string;
|
35
|
-
name:
|
36
|
+
name: string;
|
36
37
|
};
|
37
38
|
UseMutationOptions: (context: RenderContext) => {
|
38
39
|
type: string;
|
39
40
|
path: string;
|
40
|
-
name:
|
41
|
+
name: string;
|
41
42
|
};
|
42
43
|
};
|
43
44
|
export declare const UTIL_HELPERS: string[];
|
44
45
|
export declare const convertUtilsToImportList: (context: RenderContext, utils: string[], registeredUtils?: UtilMapping) => ImportObj[];
|
45
|
-
export declare const convertUtil: (context: RenderContext, util: string, registeredUtils:
|
46
|
-
export declare const getImportStatements: (list: ImportObj[], filepath?: string) =>
|
46
|
+
export declare const convertUtil: (context: RenderContext, util: string, registeredUtils: any) => ImportObj;
|
47
|
+
export declare const getImportStatements: (list: ImportObj[], filepath?: string) => (t.ImportNamespaceSpecifier | t.ImportDeclaration | t.ImportDefaultSpecifier)[];
|
47
48
|
export declare const getRelativePath: (f1: string, f2: string) => string;
|
@@ -0,0 +1,166 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.getRelativePath = exports.getImportStatements = exports.convertUtil = exports.convertUtilsToImportList = exports.UTIL_HELPERS = exports.UTILS = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const utils_1 = require("../utils");
|
29
|
+
const path_1 = require("path");
|
30
|
+
const makeReactQuerySwitch = (varName) => {
|
31
|
+
return (context) => {
|
32
|
+
switch (context.options.reactQuery.version) {
|
33
|
+
case 'v4':
|
34
|
+
return {
|
35
|
+
type: 'import',
|
36
|
+
path: '@tanstack/react-query',
|
37
|
+
name: varName
|
38
|
+
};
|
39
|
+
case 'v3':
|
40
|
+
default:
|
41
|
+
return {
|
42
|
+
type: 'import',
|
43
|
+
path: 'react-query',
|
44
|
+
name: varName
|
45
|
+
};
|
46
|
+
}
|
47
|
+
};
|
48
|
+
};
|
49
|
+
exports.UTILS = {
|
50
|
+
selectorFamily: 'recoil',
|
51
|
+
MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx',
|
52
|
+
MsgExecuteContractEncodeObject: '@cosmjs/cosmwasm-stargate',
|
53
|
+
Coin: '@cosmjs/amino',
|
54
|
+
toUtf8: '@cosmjs/encoding',
|
55
|
+
StdFee: '@cosmjs/amino',
|
56
|
+
CosmWasmClient: '@cosmjs/cosmwasm-stargate',
|
57
|
+
ExecuteResult: '@cosmjs/cosmwasm-stargate',
|
58
|
+
SigningCosmWasmClient: '@cosmjs/cosmwasm-stargate',
|
59
|
+
// react-query
|
60
|
+
useQuery: makeReactQuerySwitch('useQuery'),
|
61
|
+
UseQueryOptions: makeReactQuerySwitch('UseQueryOptions'),
|
62
|
+
useMutation: makeReactQuerySwitch('useMutation'),
|
63
|
+
UseMutationOptions: makeReactQuerySwitch('UseMutationOptions')
|
64
|
+
};
|
65
|
+
exports.UTIL_HELPERS = [
|
66
|
+
'__contractContextBase__',
|
67
|
+
];
|
68
|
+
const convertUtilsToImportList = (context, utils, registeredUtils) => {
|
69
|
+
return utils.map((util) => {
|
70
|
+
let result = null;
|
71
|
+
if (registeredUtils) {
|
72
|
+
result = (0, exports.convertUtil)(context, util, registeredUtils);
|
73
|
+
if (result) {
|
74
|
+
return result;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
result = (0, exports.convertUtil)(context, util, exports.UTILS);
|
78
|
+
if (result) {
|
79
|
+
return result;
|
80
|
+
}
|
81
|
+
throw new Error(`missing Util! ::[${util}]`);
|
82
|
+
});
|
83
|
+
};
|
84
|
+
exports.convertUtilsToImportList = convertUtilsToImportList;
|
85
|
+
const convertUtil = (context, util, registeredUtils) => {
|
86
|
+
if (!registeredUtils.hasOwnProperty(util))
|
87
|
+
return null;
|
88
|
+
if (typeof registeredUtils[util] === 'string') {
|
89
|
+
return {
|
90
|
+
type: 'import',
|
91
|
+
path: registeredUtils[util],
|
92
|
+
name: util
|
93
|
+
};
|
94
|
+
}
|
95
|
+
else if (typeof registeredUtils[util] === 'function') {
|
96
|
+
return registeredUtils[util](context);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
return registeredUtils[util];
|
100
|
+
}
|
101
|
+
};
|
102
|
+
exports.convertUtil = convertUtil;
|
103
|
+
// __helpers__
|
104
|
+
const getImportStatements = (list, filepath) => {
|
105
|
+
// swap helpers with helpers file...
|
106
|
+
const modifiedImports = list.map(imp => {
|
107
|
+
if (filepath && exports.UTIL_HELPERS.includes(imp.path)) {
|
108
|
+
const name = imp.path.replace(/__/g, '');
|
109
|
+
return {
|
110
|
+
...imp,
|
111
|
+
path: (0, exports.getRelativePath)(filepath, `./${name}`)
|
112
|
+
};
|
113
|
+
}
|
114
|
+
return imp;
|
115
|
+
});
|
116
|
+
const imports = modifiedImports.reduce((m, obj) => {
|
117
|
+
m[obj.path] = m[obj.path] || [];
|
118
|
+
const exists = m[obj.path].find((el) => el.type === obj.type && el.path === obj.path && el.name === obj.name);
|
119
|
+
// MARKED AS NOT DRY [google.protobuf names]
|
120
|
+
// TODO some have google.protobuf.Any shows up... figure out the better way to handle this
|
121
|
+
if (/\./.test(obj.name)) {
|
122
|
+
obj.name = obj.name.split('.')[obj.name.split('.').length - 1];
|
123
|
+
}
|
124
|
+
if (!exists) {
|
125
|
+
m[obj.path].push(obj);
|
126
|
+
}
|
127
|
+
return m;
|
128
|
+
}, {});
|
129
|
+
return Object.entries(imports)
|
130
|
+
.reduce((m, [importPath, imports]) => {
|
131
|
+
const defaultImports = imports.filter(a => a.type === 'default');
|
132
|
+
if (defaultImports.length) {
|
133
|
+
if (defaultImports.length > 1)
|
134
|
+
throw new Error('more than one default name NOT allowed.');
|
135
|
+
m.push(t.importDeclaration([
|
136
|
+
t.importDefaultSpecifier(t.identifier(defaultImports[0].name))
|
137
|
+
], t.stringLiteral(defaultImports[0].path)));
|
138
|
+
}
|
139
|
+
const namedImports = imports.filter(a => a.type === 'import' && (!a.importAs || (a.name === a.importAs)));
|
140
|
+
if (namedImports.length) {
|
141
|
+
m.push((0, utils_1.importStmt)(namedImports.map(i => i.name), namedImports[0].path));
|
142
|
+
}
|
143
|
+
const aliasNamedImports = imports.filter(a => a.type === 'import' && (a.importAs && (a.name !== a.importAs)));
|
144
|
+
aliasNamedImports.forEach(imp => {
|
145
|
+
m.push((0, utils_1.importAs)(imp.name, imp.importAs, imp.path));
|
146
|
+
});
|
147
|
+
const namespaced = imports.filter(a => a.type === 'namespace');
|
148
|
+
if (namespaced.length) {
|
149
|
+
if (namespaced.length > 1)
|
150
|
+
throw new Error('more than one namespaced name NOT allowed.');
|
151
|
+
m.push(t.importDeclaration([
|
152
|
+
t.importNamespaceSpecifier(t.identifier(namespaced[0].name))
|
153
|
+
], t.stringLiteral(namespaced[0].path)));
|
154
|
+
}
|
155
|
+
return m;
|
156
|
+
}, []);
|
157
|
+
};
|
158
|
+
exports.getImportStatements = getImportStatements;
|
159
|
+
const getRelativePath = (f1, f2) => {
|
160
|
+
const rel = (0, path_1.relative)((0, path_1.dirname)(f1), f2);
|
161
|
+
let importPath = rel.replace((0, path_1.extname)(rel), '');
|
162
|
+
if (!/^\./.test(importPath))
|
163
|
+
importPath = `./${importPath}`;
|
164
|
+
return importPath;
|
165
|
+
};
|
166
|
+
exports.getRelativePath = getRelativePath;
|
package/context/index.js
ADDED
@@ -0,0 +1,18 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./context"), exports);
|
18
|
+
__exportStar(require("./imports"), exports);
|
@@ -0,0 +1,238 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { camel } from 'case';
|
3
|
+
import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, FIXED_EXECUTE_PARAMS, getMessageProperties, OPTIONAL_FUNDS_PARAM, promiseTypeAnnotation, typedIdentifier, getTypeOrRef } from '../utils';
|
4
|
+
import { createTypedObjectParams, getPropertyType, getResponseType } from '../utils/types';
|
5
|
+
import { identifier, propertySignature } from '../utils/babel';
|
6
|
+
export const CONSTANT_EXEC_PARAMS = [
|
7
|
+
t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([
|
8
|
+
t.tSNumberKeyword(),
|
9
|
+
t.tsTypeReference(t.identifier('StdFee')),
|
10
|
+
t.tsLiteralType(t.stringLiteral('auto'))
|
11
|
+
])), false), t.stringLiteral('auto')),
|
12
|
+
identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true),
|
13
|
+
OPTIONAL_FUNDS_PARAM
|
14
|
+
];
|
15
|
+
export const createWasmQueryMethod = (context, jsonschema) => {
|
16
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
17
|
+
const methodName = camel(underscoreName);
|
18
|
+
const responseType = getResponseType(context, underscoreName);
|
19
|
+
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
20
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
21
|
+
const msgAction = t.identifier(underscoreName);
|
22
|
+
// If the param is an identifier, we can just use it as is
|
23
|
+
const msgActionValue = param?.type === 'Identifier'
|
24
|
+
? t.identifier(param.name)
|
25
|
+
: t.objectExpression(args);
|
26
|
+
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [param] : [], t.blockStatement([
|
27
|
+
t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('queryContractSmart')), [
|
28
|
+
t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
|
29
|
+
t.objectExpression([t.objectProperty(msgAction, msgActionValue)])
|
30
|
+
]))
|
31
|
+
]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([
|
32
|
+
t.tSTypeReference(t.identifier(responseType))
|
33
|
+
]))), true));
|
34
|
+
};
|
35
|
+
export const createQueryClass = (context, className, implementsClassName, queryMsg) => {
|
36
|
+
context.addUtil('CosmWasmClient');
|
37
|
+
const propertyNames = getMessageProperties(queryMsg)
|
38
|
+
.map((method) => Object.keys(method.properties)?.[0])
|
39
|
+
.filter(Boolean);
|
40
|
+
const bindings = propertyNames.map(camel).map(bindMethod);
|
41
|
+
const methods = getMessageProperties(queryMsg).map((schema) => {
|
42
|
+
return createWasmQueryMethod(context, schema);
|
43
|
+
});
|
44
|
+
return t.exportNamedDeclaration(classDeclaration(className, [
|
45
|
+
// client
|
46
|
+
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
|
47
|
+
// contractAddress
|
48
|
+
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())),
|
49
|
+
// constructor
|
50
|
+
t.classMethod('constructor', t.identifier('constructor'), [
|
51
|
+
typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
|
52
|
+
typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
|
53
|
+
], t.blockStatement([
|
54
|
+
// client/contract set
|
55
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))),
|
56
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))),
|
57
|
+
...bindings
|
58
|
+
])),
|
59
|
+
...methods
|
60
|
+
], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]));
|
61
|
+
};
|
62
|
+
export const getWasmMethodArgs = (context, jsonschema) => {
|
63
|
+
let keys = Object.keys(jsonschema.properties ?? {});
|
64
|
+
// only 1 degree $ref-lookup
|
65
|
+
if (!keys.length && jsonschema.$ref) {
|
66
|
+
const obj = context.refLookup(jsonschema.$ref);
|
67
|
+
// properties
|
68
|
+
if (obj) {
|
69
|
+
keys = Object.keys(obj.properties ?? {});
|
70
|
+
}
|
71
|
+
// tuple struct or otherwise, use the name of the reference
|
72
|
+
if (!keys.length && obj?.oneOf) {
|
73
|
+
// TODO????? ADAIR
|
74
|
+
}
|
75
|
+
}
|
76
|
+
const args = keys.map((prop) => {
|
77
|
+
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
|
78
|
+
});
|
79
|
+
return args;
|
80
|
+
};
|
81
|
+
export const createWasmExecMethod = (context, jsonschema) => {
|
82
|
+
context.addUtil('ExecuteResult');
|
83
|
+
context.addUtil('StdFee');
|
84
|
+
context.addUtil('Coin');
|
85
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
86
|
+
const methodName = camel(underscoreName);
|
87
|
+
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
88
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
89
|
+
const msgAction = t.identifier(underscoreName);
|
90
|
+
// If the param is an identifier, we can just use it as is
|
91
|
+
const msgActionValue = param?.type === 'Identifier'
|
92
|
+
? t.identifier(param.name)
|
93
|
+
: t.objectExpression(args);
|
94
|
+
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param
|
95
|
+
? [
|
96
|
+
// props
|
97
|
+
param,
|
98
|
+
...CONSTANT_EXEC_PARAMS
|
99
|
+
]
|
100
|
+
: CONSTANT_EXEC_PARAMS, t.blockStatement([
|
101
|
+
t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [
|
102
|
+
t.memberExpression(t.thisExpression(), t.identifier('sender')),
|
103
|
+
t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
|
104
|
+
t.objectExpression([
|
105
|
+
t.objectProperty(msgAction, msgActionValue)
|
106
|
+
]),
|
107
|
+
t.identifier('fee'),
|
108
|
+
t.identifier('memo'),
|
109
|
+
t.identifier('_funds')
|
110
|
+
])))
|
111
|
+
]),
|
112
|
+
// return type
|
113
|
+
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([
|
114
|
+
t.tSTypeReference(t.identifier('ExecuteResult'))
|
115
|
+
]))), true));
|
116
|
+
};
|
117
|
+
export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
|
118
|
+
context.addUtil('SigningCosmWasmClient');
|
119
|
+
const propertyNames = getMessageProperties(execMsg)
|
120
|
+
.map((method) => Object.keys(method.properties)?.[0])
|
121
|
+
.filter(Boolean);
|
122
|
+
const bindings = propertyNames.map(camel).map(bindMethod);
|
123
|
+
const methods = getMessageProperties(execMsg).map((schema) => {
|
124
|
+
return createWasmExecMethod(context, schema);
|
125
|
+
});
|
126
|
+
const blockStmt = [];
|
127
|
+
if (extendsClassName) {
|
128
|
+
blockStmt.push(
|
129
|
+
// super()
|
130
|
+
t.expressionStatement(t.callExpression(t.super(), [
|
131
|
+
t.identifier('client'),
|
132
|
+
t.identifier('contractAddress')
|
133
|
+
])));
|
134
|
+
}
|
135
|
+
blockStmt.push(...[
|
136
|
+
// client/contract set
|
137
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))),
|
138
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))),
|
139
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))),
|
140
|
+
...bindings
|
141
|
+
]);
|
142
|
+
const noImplicitOverride = context.options.client.noImplicitOverride &&
|
143
|
+
extendsClassName &&
|
144
|
+
context.options.client.execExtendsQuery;
|
145
|
+
return t.exportNamedDeclaration(classDeclaration(className, [
|
146
|
+
// client
|
147
|
+
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient'))), false, false, noImplicitOverride),
|
148
|
+
// sender
|
149
|
+
classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
150
|
+
// contractAddress
|
151
|
+
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()), false, false, noImplicitOverride),
|
152
|
+
// constructor
|
153
|
+
t.classMethod('constructor', t.identifier('constructor'), [
|
154
|
+
typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))),
|
155
|
+
typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
156
|
+
typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
|
157
|
+
], t.blockStatement(blockStmt)),
|
158
|
+
...methods
|
159
|
+
], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], extendsClassName ? t.identifier(extendsClassName) : null));
|
160
|
+
};
|
161
|
+
export const createExecuteInterface = (context, className, extendsClassName, execMsg) => {
|
162
|
+
const methods = getMessageProperties(execMsg).map((jsonschema) => {
|
163
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
164
|
+
const methodName = camel(underscoreName);
|
165
|
+
return createPropertyFunctionWithObjectParamsForExec(context, methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
166
|
+
});
|
167
|
+
const extendsAst = extendsClassName
|
168
|
+
? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))]
|
169
|
+
: [];
|
170
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
171
|
+
// contract address
|
172
|
+
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
173
|
+
// contract address
|
174
|
+
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
175
|
+
...methods
|
176
|
+
])));
|
177
|
+
};
|
178
|
+
export const createPropertyFunctionWithObjectParams = (context, methodName, responseType, jsonschema) => {
|
179
|
+
const obj = createTypedObjectParams(context, jsonschema);
|
180
|
+
const func = {
|
181
|
+
type: 'TSFunctionType',
|
182
|
+
typeAnnotation: promiseTypeAnnotation(responseType),
|
183
|
+
parameters: obj ? [obj] : []
|
184
|
+
};
|
185
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
186
|
+
// @ts-ignore:next-line
|
187
|
+
func));
|
188
|
+
};
|
189
|
+
export const createPropertyFunctionWithObjectParamsForExec = (context, methodName, responseType, jsonschema) => {
|
190
|
+
context.addUtil('Coin');
|
191
|
+
const obj = createTypedObjectParams(context, jsonschema);
|
192
|
+
const func = {
|
193
|
+
type: 'TSFunctionType',
|
194
|
+
typeAnnotation: promiseTypeAnnotation(responseType),
|
195
|
+
parameters: obj ? [obj, ...FIXED_EXECUTE_PARAMS] : FIXED_EXECUTE_PARAMS
|
196
|
+
};
|
197
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
198
|
+
// @ts-ignore:next-line
|
199
|
+
func));
|
200
|
+
};
|
201
|
+
export const createQueryInterface = (context, className, queryMsg) => {
|
202
|
+
const methods = getMessageProperties(queryMsg).map((jsonschema) => {
|
203
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
204
|
+
const methodName = camel(underscoreName);
|
205
|
+
const responseType = getResponseType(context, underscoreName);
|
206
|
+
return createPropertyFunctionWithObjectParams(context, methodName, responseType, jsonschema.properties[underscoreName]);
|
207
|
+
});
|
208
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([
|
209
|
+
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
210
|
+
...methods
|
211
|
+
])));
|
212
|
+
};
|
213
|
+
export const createTypeOrInterface = (context, Type, jsonschema) => {
|
214
|
+
// Handle non-object and potentially union or referenced types
|
215
|
+
if (jsonschema.type !== 'object') {
|
216
|
+
if (!jsonschema.type) {
|
217
|
+
if (jsonschema.title) {
|
218
|
+
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
219
|
+
}
|
220
|
+
else {
|
221
|
+
throw new Error('Schema must have a type or title!');
|
222
|
+
}
|
223
|
+
}
|
224
|
+
// Use getTypeOrRef to handle string, array of strings, or $ref
|
225
|
+
const typeAnnotation = getTypeOrRef(jsonschema);
|
226
|
+
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, typeAnnotation));
|
227
|
+
}
|
228
|
+
// Handle object type schemas
|
229
|
+
const props = Object.keys(jsonschema.properties ?? {}).map((prop) => {
|
230
|
+
const { type, optional } = getPropertyType(context, jsonschema, prop);
|
231
|
+
return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
|
232
|
+
});
|
233
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody([...props])));
|
234
|
+
};
|
235
|
+
export const createTypeInterface = (context, jsonschema) => {
|
236
|
+
const Type = jsonschema.title;
|
237
|
+
return createTypeOrInterface(context, Type, jsonschema);
|
238
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './client';
|