@dedot/codegen 0.17.1-next.9d03d21b.3 → 0.18.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/cjs/sol/generator/ConstructorQueryGen.js +2 -3
- package/cjs/sol/generator/EventsGen.js +8 -5
- package/cjs/sol/generator/QueryGen.js +2 -3
- package/cjs/sol/generator/TypesGen.js +1 -1
- package/package.json +10 -10
- package/sol/generator/ConstructorQueryGen.js +2 -3
- package/sol/generator/EventsGen.js +9 -6
- package/sol/generator/QueryGen.js +2 -3
- package/sol/generator/TypesGen.js +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstructorQueryGen = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
4
|
const utils_js_1 = require("../../utils.js");
|
|
6
5
|
class ConstructorQueryGen {
|
|
7
6
|
abi;
|
|
@@ -27,7 +26,7 @@ class ConstructorQueryGen {
|
|
|
27
26
|
// we use the name `_options` for the last options param
|
|
28
27
|
// This is just and edge case, so this approach works for now
|
|
29
28
|
const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
|
|
30
|
-
callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${
|
|
29
|
+
callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
|
|
31
30
|
callsOut += `new: ${this.generateMethodDef(abiItem, optionsParamName)};\n\n`;
|
|
32
31
|
return callsOut;
|
|
33
32
|
}
|
|
@@ -37,7 +36,7 @@ class ConstructorQueryGen {
|
|
|
37
36
|
}
|
|
38
37
|
generateParamsOut(abiItem) {
|
|
39
38
|
return abiItem.inputs
|
|
40
|
-
.map((input, idx) => `${
|
|
39
|
+
.map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
|
|
41
40
|
.join(', ');
|
|
42
41
|
}
|
|
43
42
|
findConstructor() {
|
|
@@ -17,7 +17,7 @@ class EventsGen {
|
|
|
17
17
|
const events = this.abi.filter((o) => o.type === 'event');
|
|
18
18
|
let eventsOut = '';
|
|
19
19
|
events.forEach((event) => {
|
|
20
|
-
const { name
|
|
20
|
+
const { name } = event;
|
|
21
21
|
eventsOut += `${(0, utils_1.stringPascalCase)(name)}: ${this.#generateEventDef(event)};\n\n`;
|
|
22
22
|
});
|
|
23
23
|
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
@@ -27,13 +27,16 @@ class EventsGen {
|
|
|
27
27
|
#generateEventDef(abiItem) {
|
|
28
28
|
const { name } = abiItem;
|
|
29
29
|
const paramsOut = this.generateParamsOut(abiItem);
|
|
30
|
-
return `GenericContractEvent<'${(0, utils_1.stringPascalCase)(name)}',
|
|
30
|
+
return `GenericContractEvent<'${(0, utils_1.stringPascalCase)(name)}', ${paramsOut}, Type>`;
|
|
31
31
|
}
|
|
32
32
|
generateParamsOut(abiItem) {
|
|
33
33
|
const { inputs } = abiItem;
|
|
34
|
-
|
|
35
|
-
.map((o
|
|
36
|
-
|
|
34
|
+
if (inputs.length > 0 && !inputs.at(0).name) {
|
|
35
|
+
return `[${inputs.map((o) => `${(0, utils_js_1.commentBlock)(`@indexed: ${o.indexed}`)}${this.typesGen.generateType(o, abiItem, 1)}`).join(', ')}]`;
|
|
36
|
+
}
|
|
37
|
+
return `{${inputs
|
|
38
|
+
.map((o, idx) => `${(0, utils_js_1.commentBlock)(`@indexed: ${o.indexed}`)}${o.name || `arg${idx}`}: ${this.typesGen.generateType(o, abiItem, 1)}`)
|
|
39
|
+
.join(', ')}}`;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
exports.EventsGen = EventsGen;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryGen = void 0;
|
|
4
4
|
const contracts_1 = require("@dedot/contracts");
|
|
5
|
-
const utils_1 = require("@dedot/utils");
|
|
6
5
|
const utils_js_1 = require("../../utils.js");
|
|
7
6
|
class QueryGen {
|
|
8
7
|
abi;
|
|
@@ -29,7 +28,7 @@ class QueryGen {
|
|
|
29
28
|
// we use the name `_options` for the last options param
|
|
30
29
|
// This is just and edge case, so this approach works for now
|
|
31
30
|
const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
|
|
32
|
-
callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${
|
|
31
|
+
callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
|
|
33
32
|
callsOut += `${(0, contracts_1.normalizeLabel)(name)}: ${this.generateMethodDef(def, optionsParamName)};\n\n`;
|
|
34
33
|
});
|
|
35
34
|
return callsOut;
|
|
@@ -44,7 +43,7 @@ class QueryGen {
|
|
|
44
43
|
}
|
|
45
44
|
generateParamsOut(abiItem) {
|
|
46
45
|
return abiItem.inputs
|
|
47
|
-
.map((input, idx) => `${
|
|
46
|
+
.map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
|
|
48
47
|
.join(', ');
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -191,7 +191,7 @@ class TypesGen {
|
|
|
191
191
|
type,
|
|
192
192
|
};
|
|
193
193
|
});
|
|
194
|
-
if (props.length > 0 && props.at(0).name
|
|
194
|
+
if (props.length > 0 && !props.at(0).name) {
|
|
195
195
|
return `[${props.map(({ type }) => `${type}`).join(', ')}]`;
|
|
196
196
|
}
|
|
197
197
|
return `{${props.map(({ name, type }) => `${name}: ${type}`).join(',\n')}}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Generate types",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"copy": "cp -R ./src/chaintypes/templates ./dist/chaintypes && cp -R ./src/chaintypes/templates ./dist/cjs/chaintypes && cp -R ./src/typink/templates ./dist/typink && cp -R ./src/typink/templates ./dist/cjs/typink && cp -R ./src/sol/templates ./dist/sol && cp -R ./src/sol/templates ./dist/cjs/sol"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dedot/api": "0.
|
|
23
|
-
"@dedot/codecs": "0.
|
|
24
|
-
"@dedot/contracts": "0.
|
|
25
|
-
"@dedot/providers": "0.
|
|
26
|
-
"@dedot/runtime-specs": "0.
|
|
27
|
-
"@dedot/shape": "0.
|
|
28
|
-
"@dedot/types": "0.
|
|
29
|
-
"@dedot/utils": "0.
|
|
22
|
+
"@dedot/api": "0.18.0",
|
|
23
|
+
"@dedot/codecs": "0.18.0",
|
|
24
|
+
"@dedot/contracts": "0.18.0",
|
|
25
|
+
"@dedot/providers": "0.18.0",
|
|
26
|
+
"@dedot/runtime-specs": "0.18.0",
|
|
27
|
+
"@dedot/shape": "0.18.0",
|
|
28
|
+
"@dedot/types": "0.18.0",
|
|
29
|
+
"@dedot/utils": "0.18.0",
|
|
30
30
|
"handlebars": "^4.7.8",
|
|
31
31
|
"prettier": "^3.6.2"
|
|
32
32
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"node": ">=18"
|
|
39
39
|
},
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "32395b356a4febaac0d52506742947c916ac9895",
|
|
42
42
|
"module": "./index.js",
|
|
43
43
|
"types": "./index.d.ts",
|
|
44
44
|
"exports": {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stringCamelCase } from '@dedot/utils';
|
|
2
1
|
import { beautifySourceCode, commentBlock, compileTemplate } from '../../utils.js';
|
|
3
2
|
export class ConstructorQueryGen {
|
|
4
3
|
abi;
|
|
@@ -24,7 +23,7 @@ export class ConstructorQueryGen {
|
|
|
24
23
|
// we use the name `_options` for the last options param
|
|
25
24
|
// This is just and edge case, so this approach works for now
|
|
26
25
|
const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
|
|
27
|
-
callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${
|
|
26
|
+
callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
|
|
28
27
|
callsOut += `new: ${this.generateMethodDef(abiItem, optionsParamName)};\n\n`;
|
|
29
28
|
return callsOut;
|
|
30
29
|
}
|
|
@@ -34,7 +33,7 @@ export class ConstructorQueryGen {
|
|
|
34
33
|
}
|
|
35
34
|
generateParamsOut(abiItem) {
|
|
36
35
|
return abiItem.inputs
|
|
37
|
-
.map((input, idx) => `${
|
|
36
|
+
.map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
|
|
38
37
|
.join(', ');
|
|
39
38
|
}
|
|
40
39
|
findConstructor() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stringPascalCase } from '@dedot/utils';
|
|
2
2
|
import { beautifySourceCode, commentBlock, compileTemplate } from '../../utils.js';
|
|
3
3
|
export class EventsGen {
|
|
4
4
|
abi;
|
|
@@ -14,7 +14,7 @@ export class EventsGen {
|
|
|
14
14
|
const events = this.abi.filter((o) => o.type === 'event');
|
|
15
15
|
let eventsOut = '';
|
|
16
16
|
events.forEach((event) => {
|
|
17
|
-
const { name
|
|
17
|
+
const { name } = event;
|
|
18
18
|
eventsOut += `${stringPascalCase(name)}: ${this.#generateEventDef(event)};\n\n`;
|
|
19
19
|
});
|
|
20
20
|
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
@@ -24,12 +24,15 @@ export class EventsGen {
|
|
|
24
24
|
#generateEventDef(abiItem) {
|
|
25
25
|
const { name } = abiItem;
|
|
26
26
|
const paramsOut = this.generateParamsOut(abiItem);
|
|
27
|
-
return `GenericContractEvent<'${stringPascalCase(name)}',
|
|
27
|
+
return `GenericContractEvent<'${stringPascalCase(name)}', ${paramsOut}, Type>`;
|
|
28
28
|
}
|
|
29
29
|
generateParamsOut(abiItem) {
|
|
30
30
|
const { inputs } = abiItem;
|
|
31
|
-
|
|
32
|
-
.map((o
|
|
33
|
-
|
|
31
|
+
if (inputs.length > 0 && !inputs.at(0).name) {
|
|
32
|
+
return `[${inputs.map((o) => `${commentBlock(`@indexed: ${o.indexed}`)}${this.typesGen.generateType(o, abiItem, 1)}`).join(', ')}]`;
|
|
33
|
+
}
|
|
34
|
+
return `{${inputs
|
|
35
|
+
.map((o, idx) => `${commentBlock(`@indexed: ${o.indexed}`)}${o.name || `arg${idx}`}: ${this.typesGen.generateType(o, abiItem, 1)}`)
|
|
36
|
+
.join(', ')}}`;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { normalizeLabel } from '@dedot/contracts';
|
|
2
|
-
import { stringCamelCase } from '@dedot/utils';
|
|
3
2
|
import { beautifySourceCode, commentBlock, compileTemplate } from '../../utils.js';
|
|
4
3
|
export class QueryGen {
|
|
5
4
|
abi;
|
|
@@ -26,7 +25,7 @@ export class QueryGen {
|
|
|
26
25
|
// we use the name `_options` for the last options param
|
|
27
26
|
// This is just and edge case, so this approach works for now
|
|
28
27
|
const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
|
|
29
|
-
callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${
|
|
28
|
+
callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
|
|
30
29
|
callsOut += `${normalizeLabel(name)}: ${this.generateMethodDef(def, optionsParamName)};\n\n`;
|
|
31
30
|
});
|
|
32
31
|
return callsOut;
|
|
@@ -41,7 +40,7 @@ export class QueryGen {
|
|
|
41
40
|
}
|
|
42
41
|
generateParamsOut(abiItem) {
|
|
43
42
|
return abiItem.inputs
|
|
44
|
-
.map((input, idx) => `${
|
|
43
|
+
.map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
|
|
45
44
|
.join(', ');
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -188,7 +188,7 @@ export class TypesGen {
|
|
|
188
188
|
type,
|
|
189
189
|
};
|
|
190
190
|
});
|
|
191
|
-
if (props.length > 0 && props.at(0).name
|
|
191
|
+
if (props.length > 0 && !props.at(0).name) {
|
|
192
192
|
return `[${props.map(({ type }) => `${type}`).join(', ')}]`;
|
|
193
193
|
}
|
|
194
194
|
return `{${props.map(({ name, type }) => `${name}: ${type}`).join(',\n')}}`;
|