@dedot/codegen 0.17.1-next.db98ff20.1 → 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.
@@ -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;
@@ -11,6 +10,7 @@ class ConstructorQueryGen {
11
10
  this.typesGen = typesGen;
12
11
  }
13
12
  generate(useSubPaths = false) {
13
+ this.typesGen.clearCache();
14
14
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
15
15
  this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'GenericConstructorCallResult', 'ConstructorCallOptions', 'ContractInstantiateResult', 'MetadataType');
16
16
  let constructor = this.findConstructor();
@@ -26,7 +26,7 @@ class ConstructorQueryGen {
26
26
  // we use the name `_options` for the last options param
27
27
  // This is just and edge case, so this approach works for now
28
28
  const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
29
- callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${(0, utils_1.stringCamelCase)(input.name || `arg${idx}`)}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
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}` : '')}`;
30
30
  callsOut += `new: ${this.generateMethodDef(abiItem, optionsParamName)};\n\n`;
31
31
  return callsOut;
32
32
  }
@@ -36,7 +36,7 @@ class ConstructorQueryGen {
36
36
  }
37
37
  generateParamsOut(abiItem) {
38
38
  return abiItem.inputs
39
- .map((input, idx) => `${(0, utils_1.stringCamelCase)(input.name || `arg${idx}`)}: ${this.typesGen.generateType(input, abiItem, 1)}`)
39
+ .map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
40
40
  .join(', ');
41
41
  }
42
42
  findConstructor() {
@@ -5,6 +5,7 @@ const utils_js_1 = require("../../utils.js");
5
5
  const ConstructorQueryGen_js_1 = require("./ConstructorQueryGen.js");
6
6
  class ConstructorTxGen extends ConstructorQueryGen_js_1.ConstructorQueryGen {
7
7
  generate(useSubPaths = false) {
8
+ this.typesGen.clearCache();
8
9
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
9
10
  this.typesGen.typeImports.addContractType('GenericConstructorTx', 'SolGenericContractApi', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericInstantiateSubmittableExtrinsic', 'MetadataType');
10
11
  let constructor = this.findConstructor();
@@ -11,12 +11,13 @@ class EventsGen {
11
11
  this.typesGen = typesGen;
12
12
  }
13
13
  generate(useSubPaths = false) {
14
+ this.typesGen.clearCache();
14
15
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
15
16
  this.typesGen.typeImports.addContractType('GenericContractEvents', 'GenericContractEvent', 'MetadataType');
16
17
  const events = this.abi.filter((o) => o.type === 'event');
17
18
  let eventsOut = '';
18
19
  events.forEach((event) => {
19
- const { name, anonymous } = event;
20
+ const { name } = event;
20
21
  eventsOut += `${(0, utils_1.stringPascalCase)(name)}: ${this.#generateEventDef(event)};\n\n`;
21
22
  });
22
23
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
@@ -26,13 +27,16 @@ class EventsGen {
26
27
  #generateEventDef(abiItem) {
27
28
  const { name } = abiItem;
28
29
  const paramsOut = this.generateParamsOut(abiItem);
29
- return `GenericContractEvent<'${(0, utils_1.stringPascalCase)(name)}', {${paramsOut}}, Type>`;
30
+ return `GenericContractEvent<'${(0, utils_1.stringPascalCase)(name)}', ${paramsOut}, Type>`;
30
31
  }
31
32
  generateParamsOut(abiItem) {
32
33
  const { inputs } = abiItem;
33
- return inputs
34
- .map((o, idx) => `${(0, utils_js_1.commentBlock)(`@indexed: ${o.indexed}`)}${(0, utils_1.stringCamelCase)(o.name || `arg${idx}`)}: ${this.typesGen.generateType(o, abiItem, 1)}`)
35
- .join(', ');
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(', ')}}`;
36
40
  }
37
41
  }
38
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;
@@ -12,6 +11,7 @@ class QueryGen {
12
11
  this.typesGen = typesGen;
13
12
  }
14
13
  generate(useSubPaths = false) {
14
+ this.typesGen.clearCache();
15
15
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
16
16
  this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult', 'MetadataType');
17
17
  const functions = this.abi.filter((item) => item.type === 'function');
@@ -28,7 +28,7 @@ class QueryGen {
28
28
  // we use the name `_options` for the last options param
29
29
  // This is just and edge case, so this approach works for now
30
30
  const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
31
- callsOut += `${(0, utils_js_1.commentBlock)(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${(0, utils_1.stringCamelCase)(input.name || `arg${idx}`)}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
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}` : '')}`;
32
32
  callsOut += `${(0, contracts_1.normalizeLabel)(name)}: ${this.generateMethodDef(def, optionsParamName)};\n\n`;
33
33
  });
34
34
  return callsOut;
@@ -43,7 +43,7 @@ class QueryGen {
43
43
  }
44
44
  generateParamsOut(abiItem) {
45
45
  return abiItem.inputs
46
- .map((input, idx) => `${(0, utils_1.stringCamelCase)(input.name || `arg${idx}`)}: ${this.typesGen.generateType(input, abiItem, 1)}`)
46
+ .map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
47
47
  .join(', ');
48
48
  }
49
49
  }
@@ -5,6 +5,7 @@ const utils_js_1 = require("../../utils.js");
5
5
  const QueryGen_js_1 = require("./QueryGen.js");
6
6
  class TxGen extends QueryGen_js_1.QueryGen {
7
7
  generate(useSubPaths = false) {
8
+ this.typesGen.clearCache();
8
9
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
9
10
  this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ContractSubmittableExtrinsic', 'MetadataType');
10
11
  const txFunctions = this.abi.filter((item) => item.type === 'function' && item.stateMutability !== 'view');
@@ -191,7 +191,7 @@ class TypesGen {
191
191
  type,
192
192
  };
193
193
  });
194
- if (props.length > 0 && props.at(0).name.length === 0) {
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')}}`;
@@ -212,5 +212,8 @@ class TypesGen {
212
212
  }
213
213
  this.typeImports.addPortableType(typeName);
214
214
  }
215
+ clearCache() {
216
+ this.typeImports.clear();
217
+ }
215
218
  }
216
219
  exports.TypesGen = TypesGen;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/codegen",
3
- "version": "0.17.1-next.db98ff20.1+db98ff20",
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.17.1-next.db98ff20.1+db98ff20",
23
- "@dedot/codecs": "0.17.1-next.db98ff20.1+db98ff20",
24
- "@dedot/contracts": "0.17.1-next.db98ff20.1+db98ff20",
25
- "@dedot/providers": "0.17.1-next.db98ff20.1+db98ff20",
26
- "@dedot/runtime-specs": "0.17.1-next.db98ff20.1+db98ff20",
27
- "@dedot/shape": "0.17.1-next.db98ff20.1+db98ff20",
28
- "@dedot/types": "0.17.1-next.db98ff20.1+db98ff20",
29
- "@dedot/utils": "0.17.1-next.db98ff20.1+db98ff20",
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": "db98ff20684d2a74b5e5402cabf43ef601d05d31",
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;
@@ -8,6 +7,7 @@ export class ConstructorQueryGen {
8
7
  this.typesGen = typesGen;
9
8
  }
10
9
  generate(useSubPaths = false) {
10
+ this.typesGen.clearCache();
11
11
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
12
12
  this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'GenericConstructorCallResult', 'ConstructorCallOptions', 'ContractInstantiateResult', 'MetadataType');
13
13
  let constructor = this.findConstructor();
@@ -23,7 +23,7 @@ export class ConstructorQueryGen {
23
23
  // we use the name `_options` for the last options param
24
24
  // This is just and edge case, so this approach works for now
25
25
  const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
26
- callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${stringCamelCase(input.name || `arg${idx}`)}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
26
+ callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, abiItem, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
27
27
  callsOut += `new: ${this.generateMethodDef(abiItem, optionsParamName)};\n\n`;
28
28
  return callsOut;
29
29
  }
@@ -33,7 +33,7 @@ export class ConstructorQueryGen {
33
33
  }
34
34
  generateParamsOut(abiItem) {
35
35
  return abiItem.inputs
36
- .map((input, idx) => `${stringCamelCase(input.name || `arg${idx}`)}: ${this.typesGen.generateType(input, abiItem, 1)}`)
36
+ .map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
37
37
  .join(', ');
38
38
  }
39
39
  findConstructor() {
@@ -2,6 +2,7 @@ import { beautifySourceCode, compileTemplate } from '../../utils.js';
2
2
  import { ConstructorQueryGen } from './ConstructorQueryGen.js';
3
3
  export class ConstructorTxGen extends ConstructorQueryGen {
4
4
  generate(useSubPaths = false) {
5
+ this.typesGen.clearCache();
5
6
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
6
7
  this.typesGen.typeImports.addContractType('GenericConstructorTx', 'SolGenericContractApi', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericInstantiateSubmittableExtrinsic', 'MetadataType');
7
8
  let constructor = this.findConstructor();
@@ -1,4 +1,4 @@
1
- import { stringCamelCase, stringPascalCase } from '@dedot/utils';
1
+ import { stringPascalCase } from '@dedot/utils';
2
2
  import { beautifySourceCode, commentBlock, compileTemplate } from '../../utils.js';
3
3
  export class EventsGen {
4
4
  abi;
@@ -8,12 +8,13 @@ export class EventsGen {
8
8
  this.typesGen = typesGen;
9
9
  }
10
10
  generate(useSubPaths = false) {
11
+ this.typesGen.clearCache();
11
12
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
12
13
  this.typesGen.typeImports.addContractType('GenericContractEvents', 'GenericContractEvent', 'MetadataType');
13
14
  const events = this.abi.filter((o) => o.type === 'event');
14
15
  let eventsOut = '';
15
16
  events.forEach((event) => {
16
- const { name, anonymous } = event;
17
+ const { name } = event;
17
18
  eventsOut += `${stringPascalCase(name)}: ${this.#generateEventDef(event)};\n\n`;
18
19
  });
19
20
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
@@ -23,12 +24,15 @@ export class EventsGen {
23
24
  #generateEventDef(abiItem) {
24
25
  const { name } = abiItem;
25
26
  const paramsOut = this.generateParamsOut(abiItem);
26
- return `GenericContractEvent<'${stringPascalCase(name)}', {${paramsOut}}, Type>`;
27
+ return `GenericContractEvent<'${stringPascalCase(name)}', ${paramsOut}, Type>`;
27
28
  }
28
29
  generateParamsOut(abiItem) {
29
30
  const { inputs } = abiItem;
30
- return inputs
31
- .map((o, idx) => `${commentBlock(`@indexed: ${o.indexed}`)}${stringCamelCase(o.name || `arg${idx}`)}: ${this.typesGen.generateType(o, abiItem, 1)}`)
32
- .join(', ');
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(', ')}}`;
33
37
  }
34
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;
@@ -9,6 +8,7 @@ export class QueryGen {
9
8
  this.typesGen = typesGen;
10
9
  }
11
10
  generate(useSubPaths = false) {
11
+ this.typesGen.clearCache();
12
12
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
13
13
  this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult', 'MetadataType');
14
14
  const functions = this.abi.filter((item) => item.type === 'function');
@@ -25,7 +25,7 @@ export class QueryGen {
25
25
  // we use the name `_options` for the last options param
26
26
  // This is just and edge case, so this approach works for now
27
27
  const optionsParamName = inputs.some(({ name }) => name === 'options') ? '_options' : 'options';
28
- callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${stringCamelCase(input.name || `arg${idx}`)}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
28
+ callsOut += `${commentBlock(inputs.map((input, idx) => `@param {${this.typesGen.generateType(input, def, 1)}} ${input.name || `arg${idx}`}`), optionsTypeName ? `@param {${optionsTypeName}} ${optionsParamName}` : '')}`;
29
29
  callsOut += `${normalizeLabel(name)}: ${this.generateMethodDef(def, optionsParamName)};\n\n`;
30
30
  });
31
31
  return callsOut;
@@ -40,7 +40,7 @@ export class QueryGen {
40
40
  }
41
41
  generateParamsOut(abiItem) {
42
42
  return abiItem.inputs
43
- .map((input, idx) => `${stringCamelCase(input.name || `arg${idx}`)}: ${this.typesGen.generateType(input, abiItem, 1)}`)
43
+ .map((input, idx) => `${input.name || `arg${idx}`}: ${this.typesGen.generateType(input, abiItem, 1)}`)
44
44
  .join(', ');
45
45
  }
46
46
  }
@@ -2,6 +2,7 @@ import { beautifySourceCode, compileTemplate } from '../../utils.js';
2
2
  import { QueryGen } from './QueryGen.js';
3
3
  export class TxGen extends QueryGen {
4
4
  generate(useSubPaths = false) {
5
+ this.typesGen.clearCache();
5
6
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
6
7
  this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ContractSubmittableExtrinsic', 'MetadataType');
7
8
  const txFunctions = this.abi.filter((item) => item.type === 'function' && item.stateMutability !== 'view');
@@ -12,4 +12,5 @@ export declare class TypesGen {
12
12
  generateType(typeDef: SolAbiTypeDef, abiItem?: SolAbiItem, nestedLevel?: number, typeOut?: boolean): string;
13
13
  generateObjectType(components: SolAbiTypeDef[], nestedLevel?: number, typeOut?: boolean): string;
14
14
  addTypeImport(typeName: string | string[]): void;
15
+ clearCache(): void;
15
16
  }
@@ -188,7 +188,7 @@ export class TypesGen {
188
188
  type,
189
189
  };
190
190
  });
191
- if (props.length > 0 && props.at(0).name.length === 0) {
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')}}`;
@@ -209,4 +209,7 @@ export class TypesGen {
209
209
  }
210
210
  this.typeImports.addPortableType(typeName);
211
211
  }
212
+ clearCache() {
213
+ this.typeImports.clear();
214
+ }
212
215
  }