@mimicprotocol/cli 0.0.1-rc.10
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 +96 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +6 -0
- package/dist/commands/codegen.js +100 -0
- package/dist/commands/compile.js +91 -0
- package/dist/commands/deploy.js +122 -0
- package/dist/commands/init.js +102 -0
- package/dist/commands/test.js +63 -0
- package/dist/errors.js +32 -0
- package/dist/helpers.js +17 -0
- package/dist/index.js +2 -0
- package/dist/lib/AbisInterfaceGenerator/AbiTypeConverter.js +137 -0
- package/dist/lib/AbisInterfaceGenerator/ArrayHandler.js +67 -0
- package/dist/lib/AbisInterfaceGenerator/ContractClassGenerator.js +70 -0
- package/dist/lib/AbisInterfaceGenerator/FunctionHandler.js +173 -0
- package/dist/lib/AbisInterfaceGenerator/ImportManager.js +17 -0
- package/dist/lib/AbisInterfaceGenerator/NameManager.js +98 -0
- package/dist/lib/AbisInterfaceGenerator/TupleHandler.js +251 -0
- package/dist/lib/AbisInterfaceGenerator/index.js +11 -0
- package/dist/lib/AbisInterfaceGenerator/types.js +4 -0
- package/dist/lib/InputsInterfaceGenerator.js +96 -0
- package/dist/lib/ManifestHandler.js +134 -0
- package/dist/lib/index.js +12 -0
- package/dist/log.js +13 -0
- package/dist/templates/eslint.config.mjs +89 -0
- package/dist/templates/manifest.yaml +9 -0
- package/dist/templates/package.json +30 -0
- package/dist/templates/src/task.ts +7 -0
- package/dist/templates/tests/Task.spec.ts +47 -0
- package/dist/templates/tests/tsconfig.json +21 -0
- package/dist/templates/tsconfig.json +6 -0
- package/dist/types.js +25 -0
- package/dist/validators.js +26 -0
- package/package.json +58 -0
|
@@ -0,0 +1,251 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const helpers_1 = require("../../helpers");
|
|
40
|
+
const types_1 = require("../../types");
|
|
41
|
+
const ArrayHandler_1 = __importDefault(require("./ArrayHandler"));
|
|
42
|
+
const FunctionHandler_1 = __importDefault(require("./FunctionHandler"));
|
|
43
|
+
const NameManager_1 = __importStar(require("./NameManager"));
|
|
44
|
+
const types_2 = require("./types");
|
|
45
|
+
class TupleHandler {
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the given ABI type string ultimately represents a tuple.
|
|
48
|
+
* E.g., 'tuple', 'tuple[]', 'tuple[2]' would all return true.
|
|
49
|
+
*/
|
|
50
|
+
static isBaseTypeATuple(abiType) {
|
|
51
|
+
return ArrayHandler_1.default.getBaseType(abiType) === types_2.TUPLE_ABI_TYPE;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the given value is a tuple class name.
|
|
55
|
+
*/
|
|
56
|
+
static isTupleClassName(value, tupleDefinitions) {
|
|
57
|
+
return [...tupleDefinitions.values()].some((def) => def.className === value);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the class name for an already defined tuple.
|
|
61
|
+
* Uses internalType or structural matching if necessary.
|
|
62
|
+
*/
|
|
63
|
+
static getClassNameForTupleDefinition(param, tupleDefinitions) {
|
|
64
|
+
if (!this.isBaseTypeATuple(param.type))
|
|
65
|
+
return undefined;
|
|
66
|
+
const baseInternalType = param.internalType ? ArrayHandler_1.default.getBaseType(param.internalType) : undefined;
|
|
67
|
+
if (baseInternalType && tupleDefinitions.has(baseInternalType))
|
|
68
|
+
return tupleDefinitions.get(baseInternalType).className;
|
|
69
|
+
const representativeParamForSearch = {
|
|
70
|
+
...param,
|
|
71
|
+
type: types_2.TUPLE_ABI_TYPE,
|
|
72
|
+
};
|
|
73
|
+
const existingByStructure = this.findMatchingDefinition(representativeParamForSearch, tupleDefinitions);
|
|
74
|
+
if (existingByStructure)
|
|
75
|
+
return existingByStructure.className;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
static extractTupleDefinitions(abi) {
|
|
79
|
+
const tupleDefinitions = new Map();
|
|
80
|
+
let tupleCounter = 0;
|
|
81
|
+
const processParam = (param) => {
|
|
82
|
+
if (!this.isBaseTypeATuple(param.type)) {
|
|
83
|
+
param.components?.forEach(processParam);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const tupleToDefine = {
|
|
87
|
+
name: param.name,
|
|
88
|
+
type: types_2.TUPLE_ABI_TYPE,
|
|
89
|
+
internalType: param.internalType,
|
|
90
|
+
components: param.components,
|
|
91
|
+
};
|
|
92
|
+
if (!tupleToDefine.components || tupleToDefine.components.length === 0)
|
|
93
|
+
return;
|
|
94
|
+
const existingClassName = this.getClassNameForTupleDefinition(tupleToDefine, tupleDefinitions);
|
|
95
|
+
if (existingClassName)
|
|
96
|
+
return existingClassName;
|
|
97
|
+
let className = `Tuple${tupleCounter++}`;
|
|
98
|
+
const baseInternalType = tupleToDefine.internalType
|
|
99
|
+
? ArrayHandler_1.default.getBaseType(tupleToDefine.internalType)
|
|
100
|
+
: undefined;
|
|
101
|
+
if (baseInternalType) {
|
|
102
|
+
const structMatch = baseInternalType.match(/struct\s+(?:\w+\.)?(\w+)/);
|
|
103
|
+
if (structMatch && structMatch[1])
|
|
104
|
+
className = structMatch[1];
|
|
105
|
+
}
|
|
106
|
+
const key = baseInternalType || className;
|
|
107
|
+
const components = this.resolveComponentNames(tupleToDefine.components, NameManager_1.NameContext.CLASS_PROPERTY);
|
|
108
|
+
tupleDefinitions.set(key, {
|
|
109
|
+
className,
|
|
110
|
+
components,
|
|
111
|
+
});
|
|
112
|
+
tupleToDefine.components.forEach((subComp) => processParam(subComp));
|
|
113
|
+
return className;
|
|
114
|
+
};
|
|
115
|
+
abi.forEach((item) => {
|
|
116
|
+
if (item.type !== 'function')
|
|
117
|
+
return;
|
|
118
|
+
item.inputs?.forEach((input) => processParam(input));
|
|
119
|
+
item.outputs?.forEach((output) => processParam(output));
|
|
120
|
+
if (item.outputs && item.outputs.length > 1) {
|
|
121
|
+
const name = this.getOutputTupleClassName(item.name);
|
|
122
|
+
const representativeOutputTuple = {
|
|
123
|
+
name,
|
|
124
|
+
type: types_2.TUPLE_ABI_TYPE,
|
|
125
|
+
internalType: `struct ${name}`,
|
|
126
|
+
components: item.outputs,
|
|
127
|
+
};
|
|
128
|
+
processParam(representativeOutputTuple);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return tupleDefinitions;
|
|
132
|
+
}
|
|
133
|
+
static findMatchingDefinition(param, definitions) {
|
|
134
|
+
if (!param.components || param.type !== types_2.TUPLE_ABI_TYPE)
|
|
135
|
+
return undefined;
|
|
136
|
+
return [...definitions.values()].find((def) => def.components.length === param.components.length &&
|
|
137
|
+
def.components.every((c, i) => c.type === param.components[i].type &&
|
|
138
|
+
(c.name === param.components[i].name || !c.name || !param.components[i].name)));
|
|
139
|
+
}
|
|
140
|
+
static generateTupleTypeString(type, components) {
|
|
141
|
+
if (!components || components.length === 0)
|
|
142
|
+
return this.mapTupleType(type);
|
|
143
|
+
const typeStrings = components.map((comp) => {
|
|
144
|
+
if (this.isBaseTypeATuple(comp.type) && comp.components)
|
|
145
|
+
return this.generateTupleTypeString(comp.type, comp.components);
|
|
146
|
+
return comp.type;
|
|
147
|
+
});
|
|
148
|
+
return this.mapTupleType(type, typeStrings.join(','));
|
|
149
|
+
}
|
|
150
|
+
static mapTupleType(abiType, tupleContent = '') {
|
|
151
|
+
if (!this.isBaseTypeATuple(abiType))
|
|
152
|
+
throw new Error(`${abiType} is not a tuple type`);
|
|
153
|
+
return abiType.replace(types_2.TUPLE_ABI_TYPE, `(${tupleContent})`);
|
|
154
|
+
}
|
|
155
|
+
static generateTupleClassesCode(tupleDefinitions, importManager, abiTypeConverter) {
|
|
156
|
+
if (tupleDefinitions.size === 0)
|
|
157
|
+
return '';
|
|
158
|
+
importManager.addType('JSON');
|
|
159
|
+
const lines = [];
|
|
160
|
+
tupleDefinitions.forEach((def) => {
|
|
161
|
+
lines.push(`export class ${def.className} {`);
|
|
162
|
+
const components = def.components;
|
|
163
|
+
components.forEach((comp) => {
|
|
164
|
+
const fieldName = comp.escapedName;
|
|
165
|
+
const componentType = abiTypeConverter.mapAbiType(comp);
|
|
166
|
+
lines.push(` readonly ${fieldName}: ${componentType}`);
|
|
167
|
+
});
|
|
168
|
+
lines.push('');
|
|
169
|
+
const constructorParams = components
|
|
170
|
+
.map((comp) => {
|
|
171
|
+
const fieldName = comp.escapedName;
|
|
172
|
+
const componentType = abiTypeConverter.mapAbiType(comp);
|
|
173
|
+
return `${fieldName}: ${componentType}`;
|
|
174
|
+
})
|
|
175
|
+
.join(', ');
|
|
176
|
+
lines.push(` constructor(${constructorParams}) {`);
|
|
177
|
+
components.forEach((comp) => {
|
|
178
|
+
const fieldName = comp.escapedName;
|
|
179
|
+
lines.push(` this.${fieldName} = ${fieldName}`);
|
|
180
|
+
});
|
|
181
|
+
lines.push(` }`);
|
|
182
|
+
lines.push('');
|
|
183
|
+
lines.push(` static parse(data: string): ${def.className} {`);
|
|
184
|
+
lines.push(` const parts = JSON.parse<${types_1.AssemblyPrimitiveTypes.string}[]>(data)`);
|
|
185
|
+
lines.push(` if (parts.length !== ${def.components.length}) throw new Error("Invalid data for tuple parsing")`);
|
|
186
|
+
const componentsWithVarNames = this.resolveComponentNames(def.components, NameManager_1.NameContext.LOCAL_VARIABLE);
|
|
187
|
+
lines.push(...this.getTupleParseMethodBody({ ...def, components: componentsWithVarNames }, abiTypeConverter, importManager));
|
|
188
|
+
const constructorArgs = componentsWithVarNames.map((r) => r.escapedName).join(', ');
|
|
189
|
+
lines.push(` return new ${def.className}(${constructorArgs})`);
|
|
190
|
+
lines.push(` }`);
|
|
191
|
+
lines.push('');
|
|
192
|
+
lines.push(` toEvmEncodeParams(): EvmEncodeParam[] {`);
|
|
193
|
+
importManager.addType('EvmEncodeParam');
|
|
194
|
+
lines.push(` return [`);
|
|
195
|
+
lines.push(...this.getTupleToEvmParamsMethodBody(def, abiTypeConverter, importManager));
|
|
196
|
+
lines.push(` ]`);
|
|
197
|
+
lines.push(` }`);
|
|
198
|
+
lines.push(`}`);
|
|
199
|
+
lines.push('');
|
|
200
|
+
});
|
|
201
|
+
return lines.join('\n');
|
|
202
|
+
}
|
|
203
|
+
static getOutputTupleClassName(functionName) {
|
|
204
|
+
const fnNamePart = functionName.replace(/[^a-zA-Z0-9_]/g, '');
|
|
205
|
+
if (!fnNamePart)
|
|
206
|
+
return 'UnnamedFunctionOutputs';
|
|
207
|
+
return `${(0, helpers_1.pascalCase)(fnNamePart)}Outputs`;
|
|
208
|
+
}
|
|
209
|
+
static getTupleParseMethodBody(def, abiTypeConverter, importManager) {
|
|
210
|
+
return def.components.map((comp, index) => {
|
|
211
|
+
const fieldName = comp.escapedName;
|
|
212
|
+
const mappedComponentType = abiTypeConverter.mapAbiType(comp);
|
|
213
|
+
const dataAccess = `parts[${index}]`;
|
|
214
|
+
const parseLogic = this.buildFieldParseLogic(dataAccess, comp, mappedComponentType, abiTypeConverter, importManager);
|
|
215
|
+
return ` const ${fieldName}: ${mappedComponentType} = ${parseLogic};`;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
static buildFieldParseLogic(dataAccessString, componentAbiParam, mappedTargetType, abiTypeConverter, importManager, depth = 0) {
|
|
219
|
+
importManager.addType('JSON');
|
|
220
|
+
const isAbiArray = ArrayHandler_1.default.isArrayType(componentAbiParam.type);
|
|
221
|
+
const baseAbiType = ArrayHandler_1.default.getBaseType(componentAbiParam.type);
|
|
222
|
+
if (isAbiArray) {
|
|
223
|
+
const elementType = ArrayHandler_1.default.getArrayType(mappedTargetType);
|
|
224
|
+
const itemVar = `item${depth}`;
|
|
225
|
+
const elementAbiParam = {
|
|
226
|
+
...componentAbiParam,
|
|
227
|
+
name: `${componentAbiParam.name || 'arrayElement'}_${itemVar}`,
|
|
228
|
+
type: ArrayHandler_1.default.getArrayType(componentAbiParam.type),
|
|
229
|
+
components: baseAbiType === types_2.TUPLE_ABI_TYPE ? componentAbiParam.components : undefined,
|
|
230
|
+
internalType: componentAbiParam.internalType
|
|
231
|
+
? ArrayHandler_1.default.getArrayType(componentAbiParam.internalType)
|
|
232
|
+
: undefined,
|
|
233
|
+
};
|
|
234
|
+
const subLogic = this.buildFieldParseLogic(itemVar, elementAbiParam, elementType, abiTypeConverter, importManager, depth + 1);
|
|
235
|
+
return `${dataAccessString} === '' ? [] : JSON.parse<${types_1.AssemblyPrimitiveTypes.string}[]>(${dataAccessString}).map<${elementType}>(((${itemVar}: ${types_1.AssemblyPrimitiveTypes.string}) => ${subLogic}))`;
|
|
236
|
+
}
|
|
237
|
+
return abiTypeConverter.generateTypeConversion(mappedTargetType, dataAccessString, false, false);
|
|
238
|
+
}
|
|
239
|
+
static getTupleToEvmParamsMethodBody(def, abiTypeConverter, importManager) {
|
|
240
|
+
return def.components.map((comp) => {
|
|
241
|
+
const fieldName = comp.escapedName;
|
|
242
|
+
const valueAccessPath = `this.${fieldName}`;
|
|
243
|
+
const paramCode = FunctionHandler_1.default.buildEvmEncodeParamCode(valueAccessPath, comp, abiTypeConverter, importManager);
|
|
244
|
+
return ` ${paramCode},`;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
static resolveComponentNames(components, context) {
|
|
248
|
+
return NameManager_1.default.resolveParameterNames(components, context, 'field');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.default = TupleHandler;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
const ContractClassGenerator_1 = __importDefault(require("./ContractClassGenerator"));
|
|
7
|
+
exports.default = {
|
|
8
|
+
generate(abi, contractName) {
|
|
9
|
+
return new ContractClassGenerator_1.default(abi).generate(contractName);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
generate(inputs) {
|
|
5
|
+
if (Object.entries(inputs).length == 0)
|
|
6
|
+
return '';
|
|
7
|
+
const convertedInputs = convertInputs(inputs);
|
|
8
|
+
const inputsMapping = generateInputsMapping(convertedInputs, inputs);
|
|
9
|
+
const imports = generateImports(convertedInputs);
|
|
10
|
+
const inputsClass = generateInputsClass(convertedInputs);
|
|
11
|
+
return [
|
|
12
|
+
'// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE MANUALLY.',
|
|
13
|
+
'',
|
|
14
|
+
imports,
|
|
15
|
+
'',
|
|
16
|
+
'declare namespace input {',
|
|
17
|
+
` ${inputsMapping}`,
|
|
18
|
+
'}',
|
|
19
|
+
'',
|
|
20
|
+
'// The class name is intentionally lowercase and plural to resemble a namespace when used in a task.',
|
|
21
|
+
'export class inputs {',
|
|
22
|
+
` ${inputsClass}`,
|
|
23
|
+
'}',
|
|
24
|
+
]
|
|
25
|
+
.join('\n')
|
|
26
|
+
.trim();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
function convertInputs(inputs) {
|
|
30
|
+
return Object.fromEntries(Object.entries(inputs).map(([name, input]) => {
|
|
31
|
+
const type = typeof input === 'string' ? input : input.type;
|
|
32
|
+
return [name, convertType(type)];
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function generateImports(inputs) {
|
|
36
|
+
const typesToImport = new Set(Object.values(inputs).filter((e) => e === 'Address' || e === 'Bytes' || e === 'BigInt'));
|
|
37
|
+
if (typesToImport.size === 0)
|
|
38
|
+
return '';
|
|
39
|
+
return `import { ${[...typesToImport].sort().join(', ')} } from '@mimicprotocol/lib-ts'`;
|
|
40
|
+
}
|
|
41
|
+
function generateInputsMapping(inputs, originalInputs) {
|
|
42
|
+
return Object.entries(inputs)
|
|
43
|
+
.map(([name, type]) => {
|
|
44
|
+
const declaration = type === 'string' || type === 'Address' || type === 'Bytes' || type === 'BigInt'
|
|
45
|
+
? `var ${name}: string | null`
|
|
46
|
+
: `const ${name}: ${type}`;
|
|
47
|
+
const originalInput = originalInputs[name];
|
|
48
|
+
const hasDescription = typeof originalInput === 'object' && !!originalInput.description;
|
|
49
|
+
return hasDescription ? `\n// ${originalInput.description}\n\t${declaration}` : declaration;
|
|
50
|
+
})
|
|
51
|
+
.join('\n');
|
|
52
|
+
}
|
|
53
|
+
function generateInputsClass(inputs) {
|
|
54
|
+
return Object.entries(inputs)
|
|
55
|
+
.map(([name, type]) => generateGetter(name, type))
|
|
56
|
+
.join('\n\n ');
|
|
57
|
+
}
|
|
58
|
+
function convertType(type) {
|
|
59
|
+
const match = type.match(/^(u?)int(\d+)?$/);
|
|
60
|
+
if (match) {
|
|
61
|
+
const isUnsigned = match[1] === 'u';
|
|
62
|
+
const size = parseInt(match[2] || '256');
|
|
63
|
+
const prefix = isUnsigned ? 'u' : 'i';
|
|
64
|
+
if (size <= 8)
|
|
65
|
+
return `${prefix}8`;
|
|
66
|
+
if (size <= 16)
|
|
67
|
+
return `${prefix}16`;
|
|
68
|
+
if (size <= 32)
|
|
69
|
+
return `${prefix}32`;
|
|
70
|
+
if (size <= 64)
|
|
71
|
+
return `${prefix}64`;
|
|
72
|
+
return 'BigInt'; // 128 and 256 go here
|
|
73
|
+
}
|
|
74
|
+
if (type.includes('address'))
|
|
75
|
+
return 'Address';
|
|
76
|
+
if (type.includes('bytes'))
|
|
77
|
+
return 'Bytes';
|
|
78
|
+
return type;
|
|
79
|
+
}
|
|
80
|
+
function generateGetter(name, type) {
|
|
81
|
+
const str = `input.${name}`;
|
|
82
|
+
let returnStr;
|
|
83
|
+
if (type === 'string')
|
|
84
|
+
returnStr = `${str}!`;
|
|
85
|
+
else if (type === 'Address')
|
|
86
|
+
returnStr = `Address.fromString(${str}!)`;
|
|
87
|
+
else if (type === 'Bytes')
|
|
88
|
+
returnStr = `Bytes.fromHexString(${str}!)`;
|
|
89
|
+
else if (type === 'BigInt')
|
|
90
|
+
returnStr = `BigInt.fromString(${str}!)`;
|
|
91
|
+
else
|
|
92
|
+
returnStr = str;
|
|
93
|
+
return `static get ${name}(): ${type} {
|
|
94
|
+
return ${returnStr}
|
|
95
|
+
}`;
|
|
96
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const js_yaml_1 = require("js-yaml");
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const zod_1 = require("zod");
|
|
40
|
+
const errors_1 = require("../errors");
|
|
41
|
+
const validators_1 = require("../validators");
|
|
42
|
+
exports.default = {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
validate(manifest) {
|
|
45
|
+
if (!manifest)
|
|
46
|
+
throw new errors_1.EmptyManifestError();
|
|
47
|
+
const mergedManifest = {
|
|
48
|
+
...manifest,
|
|
49
|
+
inputs: mergeIfUnique(manifest.inputs),
|
|
50
|
+
abis: mergeIfUnique(manifest.abis),
|
|
51
|
+
metadata: { libVersion: getLibVersion() },
|
|
52
|
+
};
|
|
53
|
+
return validators_1.ManifestValidator.parse(mergedManifest);
|
|
54
|
+
},
|
|
55
|
+
load(command, manifestDir) {
|
|
56
|
+
let loadedManifest;
|
|
57
|
+
try {
|
|
58
|
+
loadedManifest = (0, js_yaml_1.load)(fs.readFileSync(manifestDir, 'utf-8'));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
command.error(`Could not find ${manifestDir}`, {
|
|
62
|
+
code: 'FileNotFound',
|
|
63
|
+
suggestions: ['Use the -m or --manifest flag to specify the correct path'],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return this.validate(loadedManifest);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
handleValidationError(command, err);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
function mergeIfUnique(list) {
|
|
75
|
+
const merged = {};
|
|
76
|
+
for (const obj of list || []) {
|
|
77
|
+
const entries = Object.entries(obj);
|
|
78
|
+
if (entries.length !== 1)
|
|
79
|
+
throw new errors_1.MoreThanOneEntryError(entries);
|
|
80
|
+
const [key, val] = entries[0];
|
|
81
|
+
if (key in merged)
|
|
82
|
+
throw new errors_1.DuplicateEntryError(key);
|
|
83
|
+
merged[key] = val;
|
|
84
|
+
}
|
|
85
|
+
return merged;
|
|
86
|
+
}
|
|
87
|
+
function handleValidationError(command, err) {
|
|
88
|
+
let message;
|
|
89
|
+
let code;
|
|
90
|
+
let suggestions;
|
|
91
|
+
if (err instanceof errors_1.MoreThanOneEntryError) {
|
|
92
|
+
;
|
|
93
|
+
[message, code] = [err.message, err.name];
|
|
94
|
+
suggestions = [`${err.location[1][0]}: ${err.location[1][1]} might be missing a prepended '-' on manifest`];
|
|
95
|
+
}
|
|
96
|
+
else if (err instanceof errors_1.DuplicateEntryError) {
|
|
97
|
+
;
|
|
98
|
+
[message, code] = [err.message, err.name];
|
|
99
|
+
suggestions = [`Review manifest for duplicate key: ${err.duplicateKey}`];
|
|
100
|
+
}
|
|
101
|
+
else if (err instanceof errors_1.EmptyManifestError) {
|
|
102
|
+
;
|
|
103
|
+
[message, code] = [err.message, err.name];
|
|
104
|
+
suggestions = ['Verify if you are using the correct manifest file'];
|
|
105
|
+
}
|
|
106
|
+
else if (err instanceof zod_1.ZodError) {
|
|
107
|
+
;
|
|
108
|
+
[message, code] = ['Missing/Incorrect Fields', 'FieldsError'];
|
|
109
|
+
suggestions = err.errors.map((e) => `Fix Field "${e.path.join('.')}" -- ${e.message}`);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
;
|
|
113
|
+
[message, code] = [`Unkown Error: ${err}`, 'UnknownError'];
|
|
114
|
+
suggestions = [
|
|
115
|
+
'Contact the Mimic team for further assistance at our website https://www.mimic.fi/ or discord https://discord.com/invite/cpcyV9EsEg',
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
command.error(message, { code, suggestions });
|
|
119
|
+
}
|
|
120
|
+
function getLibVersion() {
|
|
121
|
+
try {
|
|
122
|
+
let currentDir = process.cwd();
|
|
123
|
+
while (currentDir !== path.dirname(currentDir)) {
|
|
124
|
+
const libPackagePath = path.join(currentDir, 'node_modules', '@mimicprotocol', 'lib-ts', 'package.json');
|
|
125
|
+
if (fs.existsSync(libPackagePath))
|
|
126
|
+
return JSON.parse(fs.readFileSync(libPackagePath, 'utf-8')).version;
|
|
127
|
+
currentDir = path.dirname(currentDir);
|
|
128
|
+
}
|
|
129
|
+
throw new Error('Could not find @mimicprotocol/lib-ts package');
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new Error(`Failed to read @mimicprotocol/lib-ts version: ${error}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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.ManifestHandler = exports.InputsInterfaceGenerator = exports.AbisInterfaceGenerator = void 0;
|
|
7
|
+
const index_1 = __importDefault(require("./AbisInterfaceGenerator/index"));
|
|
8
|
+
exports.AbisInterfaceGenerator = index_1.default;
|
|
9
|
+
const InputsInterfaceGenerator_1 = __importDefault(require("./InputsInterfaceGenerator"));
|
|
10
|
+
exports.InputsInterfaceGenerator = InputsInterfaceGenerator_1.default;
|
|
11
|
+
const ManifestHandler_1 = __importDefault(require("./ManifestHandler"));
|
|
12
|
+
exports.ManifestHandler = ManifestHandler_1.default;
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const log = {
|
|
5
|
+
startAction: (text, color) => {
|
|
6
|
+
log.stopAction();
|
|
7
|
+
core_1.ux.action.start(core_1.ux.colorize(color, text));
|
|
8
|
+
},
|
|
9
|
+
stopAction: (text) => core_1.ux.action.stop(core_1.ux.colorize('green', `${text ? `${text} ` : ''}✔️`)),
|
|
10
|
+
warnText: (text) => core_1.ux.colorize('red', text),
|
|
11
|
+
highlightText: (text) => core_1.ux.colorize('yellow', text),
|
|
12
|
+
};
|
|
13
|
+
exports.default = log;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import eslintPluginTypeScript from "@typescript-eslint/eslint-plugin"
|
|
2
|
+
import eslintParserTypeScript from "@typescript-eslint/parser"
|
|
3
|
+
import eslintPluginImport from "eslint-plugin-import"
|
|
4
|
+
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort"
|
|
5
|
+
import eslintConfigPrettier from "eslint-config-prettier"
|
|
6
|
+
import eslintPluginPrettier from "eslint-plugin-prettier"
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
{
|
|
10
|
+
ignores: ["node_modules/**", "**/dist/**", "**/build/**", "**/.prettierrc.*", "./src/types/**"]
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
files: ["**/*.{ts,tsx}"],
|
|
14
|
+
languageOptions: {
|
|
15
|
+
ecmaVersion: "latest",
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
parser: eslintParserTypeScript,
|
|
18
|
+
parserOptions: {
|
|
19
|
+
project: "./tsconfig.json"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
plugins: {
|
|
23
|
+
"@typescript-eslint": eslintPluginTypeScript,
|
|
24
|
+
prettier: eslintPluginPrettier,
|
|
25
|
+
import: eslintPluginImport,
|
|
26
|
+
"simple-import-sort": eslintPluginSimpleImportSort
|
|
27
|
+
},
|
|
28
|
+
rules: {
|
|
29
|
+
...eslintPluginTypeScript.configs.recommended.rules,
|
|
30
|
+
"@typescript-eslint/no-namespace": "off",
|
|
31
|
+
"@typescript-eslint/no-unused-vars": ["error"],
|
|
32
|
+
"@typescript-eslint/explicit-function-return-type": "error",
|
|
33
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
34
|
+
|
|
35
|
+
"prettier/prettier": [
|
|
36
|
+
"error",
|
|
37
|
+
{
|
|
38
|
+
"semi": false,
|
|
39
|
+
"singleQuote": true,
|
|
40
|
+
"trailingComma": "es5",
|
|
41
|
+
"arrowParens": "always",
|
|
42
|
+
"bracketSpacing": true,
|
|
43
|
+
"printWidth": 120,
|
|
44
|
+
"tabWidth": 2,
|
|
45
|
+
"useTabs": false
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
|
|
49
|
+
"simple-import-sort/imports": [
|
|
50
|
+
"error",
|
|
51
|
+
{
|
|
52
|
+
groups: [
|
|
53
|
+
["^@?\\w"],
|
|
54
|
+
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
|
|
55
|
+
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"simple-import-sort/exports": "error",
|
|
60
|
+
|
|
61
|
+
"comma-spacing": ["error", { before: false, after: true }],
|
|
62
|
+
"no-multiple-empty-lines": ["error", { max: 1, maxEOF: 1 }]
|
|
63
|
+
},
|
|
64
|
+
settings: {
|
|
65
|
+
"import/resolver": {
|
|
66
|
+
typescript: {
|
|
67
|
+
alwaysTryTypes: true,
|
|
68
|
+
project: "./tsconfig.json"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
// configuration for test files
|
|
74
|
+
{
|
|
75
|
+
files: ["tests/**/*.{ts,tsx}", "**/*.spec.{ts,tsx}", "**/*.test.{ts,tsx}"],
|
|
76
|
+
languageOptions: {
|
|
77
|
+
ecmaVersion: "latest",
|
|
78
|
+
sourceType: "module",
|
|
79
|
+
parser: eslintParserTypeScript,
|
|
80
|
+
parserOptions: {
|
|
81
|
+
project: "./tests/tsconfig.json"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
rules: {
|
|
85
|
+
"@typescript-eslint/no-unused-expressions": "off"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
eslintConfigPrettier
|
|
89
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mimic-task",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Unlicensed",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "yarn codegen && yarn compile",
|
|
9
|
+
"codegen": "mimic codegen",
|
|
10
|
+
"compile": "mimic compile",
|
|
11
|
+
"test": "mimic test",
|
|
12
|
+
"lint": "eslint ."
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@mimicprotocol/cli": "^0.0.1-rc.0",
|
|
16
|
+
"@mimicprotocol/lib-ts": "^0.0.1-rc.0",
|
|
17
|
+
"@mimicprotocol/test-ts": "^0.0.1-rc.0",
|
|
18
|
+
"@types/chai": "^5.2.2",
|
|
19
|
+
"@types/mocha": "^10.0.10",
|
|
20
|
+
"@types/node": "^22.10.5",
|
|
21
|
+
"assemblyscript": "0.27.36",
|
|
22
|
+
"chai": "^4.3.7",
|
|
23
|
+
"eslint": "^9.10.0",
|
|
24
|
+
"json-as": "1.1.7",
|
|
25
|
+
"mocha": "^10.2.0",
|
|
26
|
+
"tsx": "^4.20.3",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"visitor-as": "0.11.4"
|
|
29
|
+
}
|
|
30
|
+
}
|