@dedot/codegen 0.0.1-next.cb041b89.17 → 0.0.1-next.cfee875e.21

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.
@@ -42,7 +42,7 @@ class TypeImports {
42
42
  [this.knownJsonRpcTypes, `${prefix}dedot/types/json-rpc`],
43
43
  [this.codecTypes, `${prefix}dedot/codecs`],
44
44
  [this.contractTypes, `${prefix}dedot/contracts`],
45
- [this.chainTypes, prefix ? '@dedot/api/chaintypes' : 'dedot/contracts'],
45
+ [this.chainTypes, prefix ? '@dedot/api/chaintypes' : 'dedot/chaintypes'],
46
46
  [this.portableTypes, './types'],
47
47
  ];
48
48
  return toImports
@@ -7,9 +7,9 @@ class ConstructorQueryGen extends QueryGen_js_1.QueryGen {
7
7
  generate(useSubPaths = false) {
8
8
  this.typesGen.clearCache();
9
9
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
10
- this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'ConstructorCallOptions', 'ConstructorResult');
10
+ this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'ConstructorCallOptions', 'ContractInstantiateResult');
11
11
  const { constructors } = this.contractMetadata.spec;
12
- const constructorsOut = this.doGenerate(constructors);
12
+ const constructorsOut = this.doGenerate(constructors, 'ConstructorCallOptions');
13
13
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
14
14
  const template = (0, utils_js_1.compileTemplate)('typink/templates/constructor-query.hbs');
15
15
  return (0, utils_js_1.beautifySourceCode)(template({ importTypes, constructorsOut }));
@@ -18,7 +18,7 @@ class ConstructorQueryGen extends QueryGen_js_1.QueryGen {
18
18
  const { args } = def;
19
19
  args.forEach(({ type: { type } }) => this.importType(type));
20
20
  const paramsOut = this.generateParamsOut(args);
21
- return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorCallOptions) => Promise<ConstructorResult<ChainApi>>>`;
21
+ return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorCallOptions) => Promise<ContractInstantiateResult<ChainApi>>>`;
22
22
  }
23
23
  }
24
24
  exports.ConstructorQueryGen = ConstructorQueryGen;
@@ -7,9 +7,9 @@ class ConstructorTxGen extends QueryGen_js_1.QueryGen {
7
7
  generate(useSubPaths = false) {
8
8
  this.typesGen.clearCache();
9
9
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
10
- this.typesGen.typeImports.addContractType('GenericConstructorTx', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericConstructorSubmittableExtrinsic');
10
+ this.typesGen.typeImports.addContractType('GenericConstructorTx', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericInstantiateSubmittableExtrinsic');
11
11
  const { constructors } = this.contractMetadata.spec;
12
- const constructorsOut = this.doGenerate(constructors);
12
+ const constructorsOut = this.doGenerate(constructors, 'ConstructorTxOptions');
13
13
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
14
14
  const template = (0, utils_js_1.compileTemplate)('typink/templates/constructor-tx.hbs');
15
15
  return (0, utils_js_1.beautifySourceCode)(template({ importTypes, constructorsOut }));
@@ -18,7 +18,7 @@ class ConstructorTxGen extends QueryGen_js_1.QueryGen {
18
18
  const { args } = def;
19
19
  args.forEach(({ type: { type } }) => this.importType(type));
20
20
  const paramsOut = this.generateParamsOut(args);
21
- return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorTxOptions) => GenericConstructorSubmittableExtrinsic<ChainApi>>`;
21
+ return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi>>`;
22
22
  }
23
23
  }
24
24
  exports.ConstructorTxGen = ConstructorTxGen;
@@ -14,18 +14,18 @@ class QueryGen {
14
14
  generate(useSubPaths = false) {
15
15
  this.typesGen.clearCache();
16
16
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
17
- this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractResult');
17
+ this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult');
18
18
  const { messages } = this.contractMetadata.spec;
19
- const queryCallsOut = this.doGenerate(messages);
19
+ const queryCallsOut = this.doGenerate(messages, 'ContractCallOptions');
20
20
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
21
21
  const template = (0, utils_js_1.compileTemplate)('typink/templates/query.hbs');
22
22
  return (0, utils_js_1.beautifySourceCode)(template({ importTypes, queryCallsOut }));
23
23
  }
24
- doGenerate(messages) {
24
+ doGenerate(messages, optionsTypeName) {
25
25
  let callsOut = '';
26
26
  messages.forEach((messageDef) => {
27
27
  const { label, docs, selector, args } = messageDef;
28
- callsOut += `${(0, utils_js_1.commentBlock)(docs, '\n', args.map((arg) => `@param {${this.typesGen.generateType(arg.type.type, 1)}} ${(0, utils_1.stringCamelCase)(arg.label)}`), '\n', `@selector {${selector}}`)}`;
28
+ callsOut += `${(0, utils_js_1.commentBlock)(docs, '\n', args.map((arg) => `@param {${this.typesGen.generateType(arg.type.type, 1)}} ${(0, utils_1.stringCamelCase)(arg.label)}`), optionsTypeName ? `@param {${optionsTypeName}} options` : '', '\n', `@selector ${selector}`)}`;
29
29
  callsOut += `${(0, contracts_1.normalizeLabel)(label)}: ${this.generateMethodDef(messageDef)};\n\n`;
30
30
  });
31
31
  return callsOut;
@@ -36,7 +36,7 @@ class QueryGen {
36
36
  args.forEach(({ type: { type } }) => this.importType(type));
37
37
  const paramsOut = this.generateParamsOut(args);
38
38
  const typeOut = this.typesGen.generateType(returnType.type, 0, true);
39
- return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractResult<ChainApi>>>>`;
39
+ return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>>`;
40
40
  }
41
41
  generateParamsOut(args) {
42
42
  return args
@@ -7,10 +7,10 @@ class TxGen extends QueryGen_js_1.QueryGen {
7
7
  generate(useSubPaths = false) {
8
8
  this.typesGen.clearCache();
9
9
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
10
- this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ChainSubmittableExtrinsic');
10
+ this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ContractSubmittableExtrinsic');
11
11
  const { messages } = this.contractMetadata.spec;
12
12
  const txMessages = messages.filter((one) => one.mutates);
13
- const txCallsOut = this.doGenerate(txMessages);
13
+ const txCallsOut = this.doGenerate(txMessages, 'ContractTxOptions');
14
14
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
15
15
  const template = (0, utils_js_1.compileTemplate)('typink/templates/tx.hbs');
16
16
  return (0, utils_js_1.beautifySourceCode)(template({ importTypes, txCallsOut }));
@@ -19,7 +19,7 @@ class TxGen extends QueryGen_js_1.QueryGen {
19
19
  const { args } = def;
20
20
  args.forEach(({ type: { type } }) => this.importType(type));
21
21
  const paramsOut = this.generateParamsOut(args);
22
- return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractTxOptions) => ChainSubmittableExtrinsic<ChainApi>>`;
22
+ return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>>`;
23
23
  }
24
24
  }
25
25
  exports.TxGen = TxGen;
@@ -6,7 +6,7 @@ import { ContractTx } from './tx';
6
6
  import { ConstructorQuery } from './constructor-query';
7
7
  import { ConstructorTx } from './constructor-tx';
8
8
 
9
- export interface {{{contractName}}}<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends GenericContractApi<ChainApi[RpcVersion]> {
9
+ export interface {{{contractName}}}<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends GenericContractApi<ChainApi> {
10
10
  query: ContractQuery<ChainApi[RpcVersion]>;
11
11
  tx: ContractTx<ChainApi[RpcVersion]>;
12
12
  constructorQuery: ConstructorQuery<ChainApi[RpcVersion]>;
package/cjs/utils.js CHANGED
@@ -49,7 +49,7 @@ ${flatLines.map((line) => `* ${line.replaceAll(/\s+/g, ' ').trim()}`).join('\n')
49
49
  };
50
50
  exports.commentBlock = commentBlock;
51
51
  const beautifySourceCode = async (source) => {
52
- const prettierOptions = await prettier.resolveConfig(path.resolve((0, dirname_1.currentDirname)(), '../../../../.prettierrc.js'));
52
+ const prettierOptions = await prettier.resolveConfig(path.resolve((0, dirname_1.currentDirname)(), '../../../.prettierrc.cjs'));
53
53
  return prettier.format(source, { parser: 'babel-ts', ...prettierOptions });
54
54
  };
55
55
  exports.beautifySourceCode = beautifySourceCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/codegen",
3
- "version": "0.0.1-next.cb041b89.17+cb041b8",
3
+ "version": "0.0.1-next.cfee875e.21+cfee875",
4
4
  "description": "Generate types",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/codegen",
@@ -18,13 +18,13 @@
18
18
  "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"
19
19
  },
20
20
  "dependencies": {
21
- "@dedot/api": "0.0.1-next.cb041b89.17+cb041b8",
22
- "@dedot/codecs": "0.0.1-next.cb041b89.17+cb041b8",
23
- "@dedot/providers": "0.0.1-next.cb041b89.17+cb041b8",
24
- "@dedot/runtime-specs": "0.0.1-next.cb041b89.17+cb041b8",
25
- "@dedot/shape": "0.0.1-next.cb041b89.17+cb041b8",
26
- "@dedot/types": "0.0.1-next.cb041b89.17+cb041b8",
27
- "@dedot/utils": "0.0.1-next.cb041b89.17+cb041b8",
21
+ "@dedot/api": "0.0.1-next.cfee875e.21+cfee875",
22
+ "@dedot/codecs": "0.0.1-next.cfee875e.21+cfee875",
23
+ "@dedot/providers": "0.0.1-next.cfee875e.21+cfee875",
24
+ "@dedot/runtime-specs": "0.0.1-next.cfee875e.21+cfee875",
25
+ "@dedot/shape": "0.0.1-next.cfee875e.21+cfee875",
26
+ "@dedot/types": "0.0.1-next.cfee875e.21+cfee875",
27
+ "@dedot/utils": "0.0.1-next.cfee875e.21+cfee875",
28
28
  "handlebars": "^4.7.7",
29
29
  "prettier": "^3.2.5"
30
30
  },
@@ -33,7 +33,7 @@
33
33
  "directory": "dist"
34
34
  },
35
35
  "license": "Apache-2.0",
36
- "gitHead": "cb041b890507eefeb5c614d1f27105f0be404a9a",
36
+ "gitHead": "cfee875eafba07e0fbb8a72556ca549a62ddceff",
37
37
  "module": "./index.js",
38
38
  "types": "./index.d.ts",
39
39
  "exports": {
@@ -39,7 +39,7 @@ export class TypeImports {
39
39
  [this.knownJsonRpcTypes, `${prefix}dedot/types/json-rpc`],
40
40
  [this.codecTypes, `${prefix}dedot/codecs`],
41
41
  [this.contractTypes, `${prefix}dedot/contracts`],
42
- [this.chainTypes, prefix ? '@dedot/api/chaintypes' : 'dedot/contracts'],
42
+ [this.chainTypes, prefix ? '@dedot/api/chaintypes' : 'dedot/chaintypes'],
43
43
  [this.portableTypes, './types'],
44
44
  ];
45
45
  return toImports
@@ -4,9 +4,9 @@ export class ConstructorQueryGen extends QueryGen {
4
4
  generate(useSubPaths = false) {
5
5
  this.typesGen.clearCache();
6
6
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
7
- this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'ConstructorCallOptions', 'ConstructorResult');
7
+ this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'ConstructorCallOptions', 'ContractInstantiateResult');
8
8
  const { constructors } = this.contractMetadata.spec;
9
- const constructorsOut = this.doGenerate(constructors);
9
+ const constructorsOut = this.doGenerate(constructors, 'ConstructorCallOptions');
10
10
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
11
11
  const template = compileTemplate('typink/templates/constructor-query.hbs');
12
12
  return beautifySourceCode(template({ importTypes, constructorsOut }));
@@ -15,6 +15,6 @@ export class ConstructorQueryGen extends QueryGen {
15
15
  const { args } = def;
16
16
  args.forEach(({ type: { type } }) => this.importType(type));
17
17
  const paramsOut = this.generateParamsOut(args);
18
- return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorCallOptions) => Promise<ConstructorResult<ChainApi>>>`;
18
+ return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorCallOptions) => Promise<ContractInstantiateResult<ChainApi>>>`;
19
19
  }
20
20
  }
@@ -4,9 +4,9 @@ export class ConstructorTxGen extends QueryGen {
4
4
  generate(useSubPaths = false) {
5
5
  this.typesGen.clearCache();
6
6
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
7
- this.typesGen.typeImports.addContractType('GenericConstructorTx', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericConstructorSubmittableExtrinsic');
7
+ this.typesGen.typeImports.addContractType('GenericConstructorTx', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericInstantiateSubmittableExtrinsic');
8
8
  const { constructors } = this.contractMetadata.spec;
9
- const constructorsOut = this.doGenerate(constructors);
9
+ const constructorsOut = this.doGenerate(constructors, 'ConstructorTxOptions');
10
10
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
11
11
  const template = compileTemplate('typink/templates/constructor-tx.hbs');
12
12
  return beautifySourceCode(template({ importTypes, constructorsOut }));
@@ -15,6 +15,6 @@ export class ConstructorTxGen extends QueryGen {
15
15
  const { args } = def;
16
16
  args.forEach(({ type: { type } }) => this.importType(type));
17
17
  const paramsOut = this.generateParamsOut(args);
18
- return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorTxOptions) => GenericConstructorSubmittableExtrinsic<ChainApi>>`;
18
+ return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi>>`;
19
19
  }
20
20
  }
@@ -5,7 +5,7 @@ export declare class QueryGen {
5
5
  typesGen: TypesGen;
6
6
  constructor(contractMetadata: ContractMetadata, typeGen: TypesGen);
7
7
  generate(useSubPaths?: boolean): Promise<string>;
8
- doGenerate(messages: Message[]): string;
8
+ doGenerate(messages: Message[], optionsTypeName?: string): string;
9
9
  generateMethodDef(def: Message): string;
10
10
  generateParamsOut(args: ContractMessageArg[]): string;
11
11
  importType(typeId: number): any;
@@ -11,18 +11,18 @@ export class QueryGen {
11
11
  generate(useSubPaths = false) {
12
12
  this.typesGen.clearCache();
13
13
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
14
- this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractResult');
14
+ this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult');
15
15
  const { messages } = this.contractMetadata.spec;
16
- const queryCallsOut = this.doGenerate(messages);
16
+ const queryCallsOut = this.doGenerate(messages, 'ContractCallOptions');
17
17
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
18
18
  const template = compileTemplate('typink/templates/query.hbs');
19
19
  return beautifySourceCode(template({ importTypes, queryCallsOut }));
20
20
  }
21
- doGenerate(messages) {
21
+ doGenerate(messages, optionsTypeName) {
22
22
  let callsOut = '';
23
23
  messages.forEach((messageDef) => {
24
24
  const { label, docs, selector, args } = messageDef;
25
- callsOut += `${commentBlock(docs, '\n', args.map((arg) => `@param {${this.typesGen.generateType(arg.type.type, 1)}} ${stringCamelCase(arg.label)}`), '\n', `@selector {${selector}}`)}`;
25
+ callsOut += `${commentBlock(docs, '\n', args.map((arg) => `@param {${this.typesGen.generateType(arg.type.type, 1)}} ${stringCamelCase(arg.label)}`), optionsTypeName ? `@param {${optionsTypeName}} options` : '', '\n', `@selector ${selector}`)}`;
26
26
  callsOut += `${normalizeLabel(label)}: ${this.generateMethodDef(messageDef)};\n\n`;
27
27
  });
28
28
  return callsOut;
@@ -33,7 +33,7 @@ export class QueryGen {
33
33
  args.forEach(({ type: { type } }) => this.importType(type));
34
34
  const paramsOut = this.generateParamsOut(args);
35
35
  const typeOut = this.typesGen.generateType(returnType.type, 0, true);
36
- return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractResult<ChainApi>>>>`;
36
+ return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>>`;
37
37
  }
38
38
  generateParamsOut(args) {
39
39
  return args
@@ -4,10 +4,10 @@ export class TxGen extends QueryGen {
4
4
  generate(useSubPaths = false) {
5
5
  this.typesGen.clearCache();
6
6
  this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
7
- this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ChainSubmittableExtrinsic');
7
+ this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ContractSubmittableExtrinsic');
8
8
  const { messages } = this.contractMetadata.spec;
9
9
  const txMessages = messages.filter((one) => one.mutates);
10
- const txCallsOut = this.doGenerate(txMessages);
10
+ const txCallsOut = this.doGenerate(txMessages, 'ContractTxOptions');
11
11
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
12
12
  const template = compileTemplate('typink/templates/tx.hbs');
13
13
  return beautifySourceCode(template({ importTypes, txCallsOut }));
@@ -16,6 +16,6 @@ export class TxGen extends QueryGen {
16
16
  const { args } = def;
17
17
  args.forEach(({ type: { type } }) => this.importType(type));
18
18
  const paramsOut = this.generateParamsOut(args);
19
- return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractTxOptions) => ChainSubmittableExtrinsic<ChainApi>>`;
19
+ return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>>`;
20
20
  }
21
21
  }
@@ -6,7 +6,7 @@ import { ContractTx } from './tx';
6
6
  import { ConstructorQuery } from './constructor-query';
7
7
  import { ConstructorTx } from './constructor-tx';
8
8
 
9
- export interface {{{contractName}}}<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends GenericContractApi<ChainApi[RpcVersion]> {
9
+ export interface {{{contractName}}}<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends GenericContractApi<ChainApi> {
10
10
  query: ContractQuery<ChainApi[RpcVersion]>;
11
11
  tx: ContractTx<ChainApi[RpcVersion]>;
12
12
  constructorQuery: ConstructorQuery<ChainApi[RpcVersion]>;
package/utils.js CHANGED
@@ -19,7 +19,7 @@ ${flatLines.map((line) => `* ${line.replaceAll(/\s+/g, ' ').trim()}`).join('\n')
19
19
  }
20
20
  };
21
21
  export const beautifySourceCode = async (source) => {
22
- const prettierOptions = await prettier.resolveConfig(path.resolve(currentDirname(), '../../../../.prettierrc.js'));
22
+ const prettierOptions = await prettier.resolveConfig(path.resolve(currentDirname(), '../../../.prettierrc.cjs'));
23
23
  return prettier.format(source, { parser: 'babel-ts', ...prettierOptions });
24
24
  };
25
25
  export const compileTemplate = (templateFile) => {