@mimicprotocol/cli 0.0.1-rc.30 → 0.0.1-rc.32
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/CHANGELOG.md +15 -0
- package/dist/commands/init.js +8 -5
- package/dist/commands/test.js +10 -12
- package/dist/lib/AbisInterfaceGenerator/FunctionHandler.js +14 -7
- package/dist/lib/AbisInterfaceGenerator/ImportManager.js +6 -1
- package/dist/lib/AbisInterfaceGenerator/NameManager.js +14 -5
- package/dist/lib/AbisInterfaceGenerator/TupleHandler.js +0 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mimicprotocol/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.1-rc.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8853afe: Fix clashing Result import
|
|
8
|
+
- e1277c7: Refactor Result to use unwrap instead of value
|
|
9
|
+
- 323663a: Change directory to positional argument in init and test command
|
|
10
|
+
- faac37c: Ensure early returns in favor of else blocks
|
|
11
|
+
|
|
12
|
+
## 0.0.1-rc.31
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 1e48dff: Bump runner-node to version 0.0.1-rc.8
|
|
17
|
+
|
|
3
18
|
## 0.0.1-rc.30
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/commands/init.js
CHANGED
|
@@ -45,8 +45,9 @@ const packageManager_1 = require("../lib/packageManager");
|
|
|
45
45
|
const log_1 = __importDefault(require("../log"));
|
|
46
46
|
class Init extends core_1.Command {
|
|
47
47
|
async run() {
|
|
48
|
-
const { flags } = await this.parse(Init);
|
|
49
|
-
const { directory
|
|
48
|
+
const { args, flags } = await this.parse(Init);
|
|
49
|
+
const { directory } = args;
|
|
50
|
+
const { force } = flags;
|
|
50
51
|
const fullDirectory = path.resolve(directory);
|
|
51
52
|
if (force && fs.existsSync(fullDirectory) && fs.readdirSync(fullDirectory).length > 0) {
|
|
52
53
|
const shouldDelete = process.env.NODE_ENV === 'test'
|
|
@@ -73,7 +74,7 @@ class Init extends core_1.Command {
|
|
|
73
74
|
this.error(`Directory ${log_1.default.highlightText(fullDirectory)} is not empty`, {
|
|
74
75
|
code: 'DirectoryNotEmpty',
|
|
75
76
|
suggestions: [
|
|
76
|
-
'You can specify the directory
|
|
77
|
+
'You can specify the directory as a positional argument',
|
|
77
78
|
`You can ${log_1.default.warnText('overwrite')} an existing directory with --force`,
|
|
78
79
|
],
|
|
79
80
|
});
|
|
@@ -107,9 +108,11 @@ class Init extends core_1.Command {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
Init.description = 'Initializes a new Mimic-compatible project structure in the specified directory';
|
|
110
|
-
Init.examples = ['<%= config.bin %> <%= command.id %>
|
|
111
|
+
Init.examples = ['<%= config.bin %> <%= command.id %> ./new-project --force'];
|
|
112
|
+
Init.args = {
|
|
113
|
+
directory: core_1.Args.string({ description: 'Directory to initialize project', required: false, default: './' }),
|
|
114
|
+
};
|
|
111
115
|
Init.flags = {
|
|
112
|
-
directory: core_1.Flags.string({ char: 'd', description: 'Directory to initialize project', default: './' }),
|
|
113
116
|
force: core_1.Flags.boolean({ char: 'f', description: 'Overwrite existing files if they already exist', default: false }),
|
|
114
117
|
};
|
|
115
118
|
exports.default = Init;
|
package/dist/commands/test.js
CHANGED
|
@@ -34,20 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const core_1 = require("@oclif/core");
|
|
37
|
-
const child_process_1 = require("child_process");
|
|
38
37
|
const path = __importStar(require("path"));
|
|
39
38
|
const packageManager_1 = require("../lib/packageManager");
|
|
40
39
|
class Test extends core_1.Command {
|
|
41
|
-
runOrExit(cmd, args, cwd) {
|
|
42
|
-
const result = (0, child_process_1.spawnSync)(cmd, args, { cwd, stdio: 'inherit' });
|
|
43
|
-
if (result.status !== 0)
|
|
44
|
-
this.exit(result.status ?? 1);
|
|
45
|
-
}
|
|
46
40
|
async run() {
|
|
47
|
-
const { flags } = await this.parse(Test);
|
|
48
|
-
const
|
|
41
|
+
const { args, flags } = await this.parse(Test);
|
|
42
|
+
const { directory } = args;
|
|
43
|
+
const { 'skip-compile': skipCompile } = flags;
|
|
44
|
+
const baseDir = path.resolve(directory);
|
|
49
45
|
const testPath = path.join(baseDir, 'tests');
|
|
50
|
-
if (!
|
|
46
|
+
if (!skipCompile) {
|
|
51
47
|
const cg = (0, packageManager_1.execBinCommand)('mimic', ['codegen'], baseDir);
|
|
52
48
|
if (cg.status !== 0)
|
|
53
49
|
this.exit(cg.status ?? 1);
|
|
@@ -60,9 +56,11 @@ class Test extends core_1.Command {
|
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
Test.description = 'Runs task tests';
|
|
63
|
-
Test.examples = ['<%= config.bin %> <%= command.id %>
|
|
59
|
+
Test.examples = ['<%= config.bin %> <%= command.id %> ./'];
|
|
60
|
+
Test.args = {
|
|
61
|
+
directory: core_1.Args.string({ description: 'task directory', required: false, default: './' }),
|
|
62
|
+
};
|
|
64
63
|
Test.flags = {
|
|
65
|
-
|
|
66
|
-
skipCompile: core_1.Flags.boolean({ description: 'skip codegen and compile steps' }),
|
|
64
|
+
'skip-compile': core_1.Flags.boolean({ description: 'skip codegen and compile steps' }),
|
|
67
65
|
};
|
|
68
66
|
exports.default = Test;
|
|
@@ -91,14 +91,18 @@ class FunctionHandler {
|
|
|
91
91
|
const methodName = fn.escapedName || fn.name;
|
|
92
92
|
const capitalizedName = this.getCapitalizedName(fn);
|
|
93
93
|
const isPayable = fn.stateMutability === 'payable';
|
|
94
|
-
const
|
|
94
|
+
const hasValueParameter = inputs.some((input) => input.escapedName === 'value');
|
|
95
|
+
const payableParamName = isPayable && hasValueParameter ? '_payableValue' : 'value';
|
|
96
|
+
const fullMethodParams = methodParams.concat(isPayable
|
|
97
|
+
? `${methodParams.length > 0 ? ', ' : ''}${payableParamName}: ${types_1.LibTypes.BigInt} = ${types_1.LibTypes.BigInt}.zero()`
|
|
98
|
+
: '');
|
|
95
99
|
lines.push(`${methodName}(${fullMethodParams}): ${returnType} {`);
|
|
96
100
|
lines.push(`const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
|
|
97
101
|
importManager.addType(types_1.LibTypes.Bytes);
|
|
98
102
|
importManager.addType('EvmCallBuilder');
|
|
99
103
|
if (isPayable)
|
|
100
104
|
importManager.addType(types_1.LibTypes.BigInt);
|
|
101
|
-
lines.push(`return EvmCallBuilder.forChain(this._chainId).addCall(this._address, encodedData${isPayable ?
|
|
105
|
+
lines.push(`return EvmCallBuilder.forChain(this._chainId).addCall(this._address, encodedData${isPayable ? `, ${payableParamName}` : ''})`);
|
|
102
106
|
lines.push(`}`);
|
|
103
107
|
lines.push('');
|
|
104
108
|
}
|
|
@@ -113,18 +117,21 @@ class FunctionHandler {
|
|
|
113
117
|
const isVoid = returnType === 'void';
|
|
114
118
|
if (isVoid)
|
|
115
119
|
importManager.addType(types_1.LibTypes.Void);
|
|
116
|
-
const
|
|
120
|
+
const resultIdentifier = NameManager_1.default.getImportNameForCode('Result');
|
|
121
|
+
const resultReturnType = isVoid
|
|
122
|
+
? `${resultIdentifier}<${types_1.LibTypes.Void}, string>`
|
|
123
|
+
: `${resultIdentifier}<${returnType}, string>`;
|
|
117
124
|
lines.push(`${methodName}(${methodParams}): ${resultReturnType} {`);
|
|
118
125
|
lines.push(`const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
|
|
119
126
|
const contractCallLine = `environment.evmCallQuery(this._address, this._chainId, encodedData.toHexString(), this._timestamp)`;
|
|
120
127
|
lines.push(`const response = ${contractCallLine}`);
|
|
121
|
-
lines.push(`if (response.isError) return
|
|
128
|
+
lines.push(`if (response.isError) return ${resultIdentifier}.err<${isVoid ? types_1.LibTypes.Void : returnType}, string>(response.error)`);
|
|
122
129
|
if (isVoid) {
|
|
123
|
-
lines.push(`return
|
|
130
|
+
lines.push(`return ${resultIdentifier}.ok<${types_1.LibTypes.Void}, string>(new ${types_1.LibTypes.Void}())`);
|
|
124
131
|
}
|
|
125
132
|
else {
|
|
126
|
-
lines.push(`const decoded = ${contractName}Utils.decode${capitalizedName}(response.
|
|
127
|
-
lines.push(`return
|
|
133
|
+
lines.push(`const decoded = ${contractName}Utils.decode${capitalizedName}(response.unwrap())`);
|
|
134
|
+
lines.push(`return ${resultIdentifier}.ok<${returnType}, string>(decoded)`);
|
|
128
135
|
}
|
|
129
136
|
lines.push(`}`);
|
|
130
137
|
lines.push('');
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const NameManager_1 = __importDefault(require("./NameManager"));
|
|
3
7
|
class ImportManager {
|
|
4
8
|
constructor() {
|
|
5
9
|
this.types = new Set();
|
|
@@ -11,7 +15,8 @@ class ImportManager {
|
|
|
11
15
|
if (this.types.size === 0)
|
|
12
16
|
return '';
|
|
13
17
|
const sortedTypes = [...this.types].sort((a, b) => String(a).localeCompare(String(b)));
|
|
14
|
-
|
|
18
|
+
const importIdentifiers = sortedTypes.map((type) => NameManager_1.default.formatImportStatement(type));
|
|
19
|
+
return `import { ${importIdentifiers.join(', ')} } from '@mimicprotocol/lib-ts'`;
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
exports.default = ImportManager;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NameContext = void 0;
|
|
4
|
-
const types_1 = require("../../types");
|
|
5
4
|
var NameContext;
|
|
6
5
|
(function (NameContext) {
|
|
7
6
|
NameContext["FUNCTION_PARAMETER"] = "function_parameter";
|
|
8
7
|
NameContext["LOCAL_VARIABLE"] = "local_variable";
|
|
9
8
|
NameContext["CLASS_PROPERTY"] = "class_property";
|
|
10
9
|
NameContext["METHOD_NAME"] = "method_name";
|
|
11
|
-
NameContext["TUPLE_CLASS_NAME"] = "tuple_class_name";
|
|
12
10
|
})(NameContext || (exports.NameContext = NameContext = {}));
|
|
13
11
|
class NameManager {
|
|
14
12
|
static resolveNameConflicts(names, context) {
|
|
@@ -41,6 +39,17 @@ class NameManager {
|
|
|
41
39
|
escapedName: resolvedNames[index],
|
|
42
40
|
}));
|
|
43
41
|
}
|
|
42
|
+
static getImportNameForCode(type) {
|
|
43
|
+
const alias = this.getImportAlias(type);
|
|
44
|
+
return alias ?? type;
|
|
45
|
+
}
|
|
46
|
+
static formatImportStatement(type) {
|
|
47
|
+
const alias = this.getImportAlias(type);
|
|
48
|
+
return alias ? `${type} as ${alias}` : type;
|
|
49
|
+
}
|
|
50
|
+
static getImportAlias(type) {
|
|
51
|
+
return this.IMPORT_ALIASES[type] ?? null;
|
|
52
|
+
}
|
|
44
53
|
static hasConflict(name, context) {
|
|
45
54
|
if (this.RESERVED_BY_CONTEXT[context]?.has(name))
|
|
46
55
|
return true;
|
|
@@ -68,13 +77,14 @@ class NameManager {
|
|
|
68
77
|
return '_prop';
|
|
69
78
|
case NameContext.METHOD_NAME:
|
|
70
79
|
return '_';
|
|
71
|
-
case NameContext.TUPLE_CLASS_NAME:
|
|
72
|
-
return '_class';
|
|
73
80
|
default:
|
|
74
81
|
return '_safe';
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
}
|
|
85
|
+
NameManager.IMPORT_ALIASES = {
|
|
86
|
+
Result: '_Result',
|
|
87
|
+
};
|
|
78
88
|
NameManager.RESERVED_BY_CONTEXT = {
|
|
79
89
|
[NameContext.FUNCTION_PARAMETER]: new Set([
|
|
80
90
|
'response',
|
|
@@ -97,7 +107,6 @@ NameManager.RESERVED_BY_CONTEXT = {
|
|
|
97
107
|
'timestamp',
|
|
98
108
|
]),
|
|
99
109
|
[NameContext.METHOD_NAME]: new Set(['constructor']),
|
|
100
|
-
[NameContext.TUPLE_CLASS_NAME]: new Set([...Object.values(types_1.LibTypes), 'JSON']),
|
|
101
110
|
};
|
|
102
111
|
NameManager.INTERNAL_NAME_PATTERNS = [/^item\d+$/, /^s\d+$/];
|
|
103
112
|
exports.default = NameManager;
|
|
@@ -103,7 +103,6 @@ class TupleHandler {
|
|
|
103
103
|
if (structMatch && structMatch[1])
|
|
104
104
|
className = structMatch[1];
|
|
105
105
|
}
|
|
106
|
-
className = NameManager_1.default.escapeName(className, NameManager_1.NameContext.TUPLE_CLASS_NAME);
|
|
107
106
|
const key = baseInternalType || className;
|
|
108
107
|
const components = this.resolveComponentNames(tupleToDefine.components, NameManager_1.NameContext.CLASS_PROPERTY);
|
|
109
108
|
tupleDefinitions.set(key, {
|
package/dist/types.js
CHANGED
|
@@ -7,9 +7,9 @@ var LibTypes;
|
|
|
7
7
|
LibTypes["Address"] = "Address";
|
|
8
8
|
LibTypes["Bytes"] = "Bytes";
|
|
9
9
|
LibTypes["ChainId"] = "ChainId";
|
|
10
|
-
LibTypes["TokenAmount"] = "TokenAmount";
|
|
11
10
|
LibTypes["Void"] = "Void";
|
|
12
11
|
LibTypes["Result"] = "Result";
|
|
12
|
+
LibTypes["JSON"] = "JSON";
|
|
13
13
|
})(LibTypes || (exports.LibTypes = LibTypes = {}));
|
|
14
14
|
var AssemblyPrimitiveTypes;
|
|
15
15
|
(function (AssemblyPrimitiveTypes) {
|