@dedot/codegen 0.0.1-next.fecbe32d.13 → 0.1.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/{generator → chaintypes/generator}/ApiGen.d.ts +16 -16
- package/{generator → chaintypes/generator}/ConstsGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/ConstsGen.js +5 -5
- package/{generator → chaintypes/generator}/ErrorsGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/ErrorsGen.js +9 -9
- package/{generator → chaintypes/generator}/EventsGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/EventsGen.js +9 -9
- package/{generator → chaintypes/generator}/IndexGen.d.ts +1 -1
- package/chaintypes/generator/IndexGen.js +17 -0
- package/{generator → chaintypes/generator}/JsonRpcGen.d.ts +3 -2
- package/{generator → chaintypes/generator}/JsonRpcGen.js +8 -8
- package/{generator → chaintypes/generator}/QueryGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/QueryGen.js +15 -15
- package/{generator → chaintypes/generator}/RuntimeApisGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/RuntimeApisGen.js +11 -11
- package/{generator → chaintypes/generator}/TxGen.d.ts +1 -1
- package/{generator → chaintypes/generator}/TxGen.js +16 -14
- package/chaintypes/generator/TypesGen.d.ts +11 -0
- package/chaintypes/generator/TypesGen.js +55 -0
- package/chaintypes/index.d.ts +3 -0
- package/chaintypes/index.js +49 -0
- package/chaintypes/templates/consts.hbs +7 -0
- package/chaintypes/templates/errors.hbs +7 -0
- package/chaintypes/templates/events.hbs +7 -0
- package/chaintypes/templates/index.hbs +27 -0
- package/chaintypes/templates/json-rpc.hbs +5 -0
- package/chaintypes/templates/query.hbs +7 -0
- package/chaintypes/templates/runtime.hbs +8 -0
- package/chaintypes/templates/tx.hbs +9 -0
- package/{templates → chaintypes/templates}/types.hbs +1 -1
- package/cjs/{generator → chaintypes/generator}/ConstsGen.js +5 -5
- package/cjs/{generator → chaintypes/generator}/ErrorsGen.js +9 -9
- package/cjs/{generator → chaintypes/generator}/EventsGen.js +9 -9
- package/cjs/chaintypes/generator/IndexGen.js +21 -0
- package/cjs/{generator → chaintypes/generator}/JsonRpcGen.js +10 -10
- package/cjs/{generator → chaintypes/generator}/QueryGen.js +15 -15
- package/cjs/{generator → chaintypes/generator}/RuntimeApisGen.js +14 -14
- package/cjs/{generator → chaintypes/generator}/TxGen.js +16 -14
- package/cjs/chaintypes/generator/TypesGen.js +59 -0
- package/cjs/chaintypes/index.js +77 -0
- package/cjs/chaintypes/templates/consts.hbs +7 -0
- package/cjs/chaintypes/templates/errors.hbs +7 -0
- package/cjs/chaintypes/templates/events.hbs +7 -0
- package/cjs/chaintypes/templates/index.hbs +27 -0
- package/cjs/chaintypes/templates/json-rpc.hbs +5 -0
- package/cjs/chaintypes/templates/query.hbs +7 -0
- package/cjs/chaintypes/templates/runtime.hbs +8 -0
- package/cjs/chaintypes/templates/tx.hbs +9 -0
- package/cjs/{templates → chaintypes/templates}/types.hbs +1 -1
- package/cjs/index.js +4 -62
- package/cjs/{generator/TypesGen.js → shared/BaseTypesGen.js} +111 -159
- package/cjs/{generator → shared}/TypeImports.js +27 -9
- package/cjs/shared/index.js +19 -0
- package/cjs/{generator → shared}/known-codecs.js +23 -4
- package/cjs/typink/generator/ConstructorQueryGen.js +24 -0
- package/cjs/typink/generator/ConstructorTxGen.js +24 -0
- package/cjs/typink/generator/EventsGen.js +35 -0
- package/cjs/typink/generator/IndexGen.js +24 -0
- package/cjs/typink/generator/QueryGen.js +72 -0
- package/cjs/typink/generator/TxGen.js +25 -0
- package/cjs/typink/generator/TypesGen.js +28 -0
- package/cjs/typink/generator/index.js +23 -0
- package/cjs/typink/index.js +40 -0
- package/cjs/typink/templates/constructor-query.hbs +7 -0
- package/cjs/typink/templates/constructor-tx.hbs +7 -0
- package/cjs/typink/templates/events.hbs +8 -0
- package/cjs/typink/templates/index.hbs +16 -0
- package/cjs/typink/templates/query.hbs +7 -0
- package/cjs/typink/templates/tx.hbs +7 -0
- package/cjs/typink/templates/types.hbs +5 -0
- package/cjs/{generator/utils.js → utils.js} +4 -4
- package/index.d.ts +2 -3
- package/index.js +2 -48
- package/package.json +15 -17
- package/{generator/TypesGen.d.ts → shared/BaseTypesGen.d.ts} +12 -11
- package/{generator/TypesGen.js → shared/BaseTypesGen.js} +108 -156
- package/{generator → shared}/TypeImports.d.ts +12 -3
- package/{generator → shared}/TypeImports.js +27 -9
- package/shared/index.d.ts +3 -0
- package/shared/index.js +3 -0
- package/{generator → shared}/known-codecs.d.ts +1 -1
- package/{generator → shared}/known-codecs.js +21 -2
- package/typink/generator/ConstructorQueryGen.d.ts +6 -0
- package/typink/generator/ConstructorQueryGen.js +20 -0
- package/typink/generator/ConstructorTxGen.d.ts +6 -0
- package/typink/generator/ConstructorTxGen.js +20 -0
- package/typink/generator/EventsGen.d.ts +7 -0
- package/typink/generator/EventsGen.js +31 -0
- package/typink/generator/IndexGen.d.ts +6 -0
- package/typink/generator/IndexGen.js +20 -0
- package/typink/generator/QueryGen.d.ts +12 -0
- package/typink/generator/QueryGen.js +68 -0
- package/typink/generator/TxGen.d.ts +6 -0
- package/typink/generator/TxGen.js +21 -0
- package/typink/generator/TypesGen.d.ts +7 -0
- package/typink/generator/TypesGen.js +24 -0
- package/typink/generator/index.d.ts +7 -0
- package/typink/generator/index.js +7 -0
- package/typink/index.d.ts +2 -0
- package/typink/index.js +33 -0
- package/typink/templates/constructor-query.hbs +7 -0
- package/typink/templates/constructor-tx.hbs +7 -0
- package/typink/templates/events.hbs +8 -0
- package/typink/templates/index.hbs +16 -0
- package/typink/templates/query.hbs +7 -0
- package/typink/templates/tx.hbs +7 -0
- package/typink/templates/types.hbs +5 -0
- package/{generator/utils.d.ts → utils.d.ts} +1 -1
- package/{generator/utils.js → utils.js} +4 -4
- package/cjs/generator/IndexGen.js +0 -17
- package/cjs/templates/consts.hbs +0 -7
- package/cjs/templates/errors.hbs +0 -7
- package/cjs/templates/events.hbs +0 -7
- package/cjs/templates/index.hbs +0 -22
- package/cjs/templates/json-rpc.hbs +0 -5
- package/cjs/templates/query.hbs +0 -7
- package/cjs/templates/runtime.hbs +0 -8
- package/cjs/templates/tx.hbs +0 -9
- package/generator/IndexGen.js +0 -13
- package/templates/consts.hbs +0 -7
- package/templates/errors.hbs +0 -7
- package/templates/events.hbs +0 -7
- package/templates/index.hbs +0 -22
- package/templates/json-rpc.hbs +0 -5
- package/templates/query.hbs +0 -7
- package/templates/runtime.hbs +0 -8
- package/templates/tx.hbs +0 -9
- /package/{generator → chaintypes/generator}/ApiGen.js +0 -0
- /package/{generator → chaintypes/generator}/index.d.ts +0 -0
- /package/{generator → chaintypes/generator}/index.js +0 -0
- /package/cjs/{generator → chaintypes/generator}/ApiGen.js +0 -0
- /package/cjs/{generator → chaintypes/generator}/index.js +0 -0
- /package/cjs/{generator/dirname.js → dirname.js} +0 -0
- /package/{generator/dirname.d.ts → dirname.d.ts} +0 -0
- /package/{generator/dirname.js → dirname.js} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContractMetadata, ContractMessage, ContractMessageArg } from '@dedot/contracts';
|
|
2
|
+
import { TypesGen } from './TypesGen.js';
|
|
3
|
+
export declare class QueryGen {
|
|
4
|
+
contractMetadata: ContractMetadata;
|
|
5
|
+
typesGen: TypesGen;
|
|
6
|
+
constructor(contractMetadata: ContractMetadata, typeGen: TypesGen);
|
|
7
|
+
generate(useSubPaths?: boolean): Promise<string>;
|
|
8
|
+
doGenerate(messages: ContractMessage[], optionsTypeName?: string): string;
|
|
9
|
+
generateMethodDef(def: ContractMessage): string;
|
|
10
|
+
generateParamsOut(args: ContractMessageArg[]): string;
|
|
11
|
+
importType(typeId: number): any;
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { normalizeContractTypeDef, normalizeLabel, } from '@dedot/contracts';
|
|
2
|
+
import { stringCamelCase } from '@dedot/utils';
|
|
3
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from '../../utils.js';
|
|
4
|
+
export class QueryGen {
|
|
5
|
+
contractMetadata;
|
|
6
|
+
typesGen;
|
|
7
|
+
constructor(contractMetadata, typeGen) {
|
|
8
|
+
this.contractMetadata = contractMetadata;
|
|
9
|
+
this.typesGen = typeGen;
|
|
10
|
+
}
|
|
11
|
+
generate(useSubPaths = false) {
|
|
12
|
+
this.typesGen.clearCache();
|
|
13
|
+
this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
|
|
14
|
+
this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult');
|
|
15
|
+
const { messages } = this.contractMetadata.spec;
|
|
16
|
+
const queryCallsOut = this.doGenerate(messages, 'ContractCallOptions');
|
|
17
|
+
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
18
|
+
const template = compileTemplate('typink/templates/query.hbs');
|
|
19
|
+
return beautifySourceCode(template({ importTypes, queryCallsOut }));
|
|
20
|
+
}
|
|
21
|
+
doGenerate(messages, optionsTypeName) {
|
|
22
|
+
let callsOut = '';
|
|
23
|
+
messages.forEach((messageDef) => {
|
|
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)}`), optionsTypeName ? `@param {${optionsTypeName}} options` : '', '\n', `@selector ${selector}`)}`;
|
|
26
|
+
callsOut += `${normalizeLabel(label)}: ${this.generateMethodDef(messageDef)};\n\n`;
|
|
27
|
+
});
|
|
28
|
+
return callsOut;
|
|
29
|
+
}
|
|
30
|
+
generateMethodDef(def) {
|
|
31
|
+
const { args, returnType } = def;
|
|
32
|
+
this.importType(returnType.type);
|
|
33
|
+
args.forEach(({ type: { type } }) => this.importType(type));
|
|
34
|
+
const paramsOut = this.generateParamsOut(args);
|
|
35
|
+
const typeOut = this.typesGen.generateType(returnType.type, 0, true);
|
|
36
|
+
return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>>`;
|
|
37
|
+
}
|
|
38
|
+
generateParamsOut(args) {
|
|
39
|
+
return args
|
|
40
|
+
.map(({ type: { type }, label }) => `${stringCamelCase(label)}: ${this.typesGen.generateType(type, 1)}`)
|
|
41
|
+
.join(', ');
|
|
42
|
+
}
|
|
43
|
+
importType(typeId) {
|
|
44
|
+
const contractType = this.contractMetadata.types[typeId];
|
|
45
|
+
const typeDef = normalizeContractTypeDef(this.contractMetadata.types[typeId].type.def);
|
|
46
|
+
if (this.typesGen.includedTypes[contractType.id]) {
|
|
47
|
+
this.typesGen.addTypeImport(this.typesGen.includedTypes[contractType.id].name);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { type, value } = typeDef;
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'Compact':
|
|
53
|
+
case 'Primitive':
|
|
54
|
+
case 'BitSequence':
|
|
55
|
+
return;
|
|
56
|
+
case 'Struct':
|
|
57
|
+
return value.fields.forEach(({ typeId }) => this.importType(typeId));
|
|
58
|
+
case 'Enum':
|
|
59
|
+
return value.members.forEach(({ fields }) => fields.map(({ typeId }) => this.importType(typeId)).flat());
|
|
60
|
+
case 'Tuple':
|
|
61
|
+
return value.fields.forEach((typeId) => this.importType(typeId));
|
|
62
|
+
case 'SizedVec':
|
|
63
|
+
return this.importType(value.typeParam);
|
|
64
|
+
case 'Sequence':
|
|
65
|
+
return this.importType(value.typeParam);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { beautifySourceCode, compileTemplate } from '../../utils.js';
|
|
2
|
+
import { QueryGen } from './QueryGen.js';
|
|
3
|
+
export class TxGen extends QueryGen {
|
|
4
|
+
generate(useSubPaths = false) {
|
|
5
|
+
this.typesGen.clearCache();
|
|
6
|
+
this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
|
|
7
|
+
this.typesGen.typeImports.addContractType('GenericContractTx', 'GenericContractTxCall', 'ContractTxOptions', 'ContractSubmittableExtrinsic');
|
|
8
|
+
const { messages } = this.contractMetadata.spec;
|
|
9
|
+
const txMessages = messages.filter((one) => one.mutates);
|
|
10
|
+
const txCallsOut = this.doGenerate(txMessages, 'ContractTxOptions');
|
|
11
|
+
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
12
|
+
const template = compileTemplate('typink/templates/tx.hbs');
|
|
13
|
+
return beautifySourceCode(template({ importTypes, txCallsOut }));
|
|
14
|
+
}
|
|
15
|
+
generateMethodDef(def) {
|
|
16
|
+
const { args } = def;
|
|
17
|
+
args.forEach(({ type: { type } }) => this.importType(type));
|
|
18
|
+
const paramsOut = this.generateParamsOut(args);
|
|
19
|
+
return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>>`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContractMetadata } from '@dedot/contracts';
|
|
2
|
+
import { BaseTypesGen } from '../../shared/index.js';
|
|
3
|
+
export declare class TypesGen extends BaseTypesGen {
|
|
4
|
+
contractMetadata: ContractMetadata;
|
|
5
|
+
constructor(contractMetadata: ContractMetadata);
|
|
6
|
+
generate(useSubPaths?: boolean): Promise<string>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { extractContractTypes } from '@dedot/contracts';
|
|
2
|
+
import { BaseTypesGen } from '../../shared/index.js';
|
|
3
|
+
import { beautifySourceCode, compileTemplate } from '../../utils.js';
|
|
4
|
+
const SKIP_TYPES = ['Result', 'Option'];
|
|
5
|
+
export class TypesGen extends BaseTypesGen {
|
|
6
|
+
contractMetadata;
|
|
7
|
+
constructor(contractMetadata) {
|
|
8
|
+
super(extractContractTypes(contractMetadata));
|
|
9
|
+
this.contractMetadata = contractMetadata;
|
|
10
|
+
this.skipTypes = SKIP_TYPES;
|
|
11
|
+
this.includedTypes = this.includeTypes();
|
|
12
|
+
}
|
|
13
|
+
generate(useSubPaths = false) {
|
|
14
|
+
let defTypeOut = '';
|
|
15
|
+
Object.values(this.includedTypes)
|
|
16
|
+
.filter(({ skip, knownType }) => !(skip || knownType))
|
|
17
|
+
.forEach(({ nameOut, id }) => {
|
|
18
|
+
defTypeOut += `export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
|
|
19
|
+
});
|
|
20
|
+
const importTypes = this.typeImports.toImports({ excludeModules: ['./types'], useSubPaths });
|
|
21
|
+
const template = compileTemplate('typink/templates/types.hbs');
|
|
22
|
+
return beautifySourceCode(template({ importTypes, defTypeOut }));
|
|
23
|
+
}
|
|
24
|
+
}
|
package/typink/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parseRawMetadata } from '@dedot/contracts';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { IndexGen, QueryGen, EventsGen, TxGen, TypesGen, ConstructorTxGen, ConstructorQueryGen, } from './generator/index.js';
|
|
5
|
+
export async function generateContractTypes(metadata, contract, outDir = '.', extension = 'd.ts', useSubPaths = false) {
|
|
6
|
+
let contractMetadata = typeof metadata === 'string' ? parseRawMetadata(metadata) : metadata;
|
|
7
|
+
contract = contract || contractMetadata.contract.name;
|
|
8
|
+
const dirPath = path.resolve(outDir, contract);
|
|
9
|
+
const typesFileName = path.join(dirPath, `types.${extension}`);
|
|
10
|
+
const queryTypesFileName = path.join(dirPath, `query.${extension}`);
|
|
11
|
+
const txTypesFileName = path.join(dirPath, `tx.${extension}`);
|
|
12
|
+
const constructorTxTypesFileName = path.join(dirPath, `constructor-tx.${extension}`);
|
|
13
|
+
const constructorQueryTypesFileName = path.join(dirPath, `constructor-query.${extension}`);
|
|
14
|
+
const eventsTypesFile = path.join(dirPath, `events.${extension}`);
|
|
15
|
+
const indexTypesFileName = path.join(dirPath, `index.${extension}`);
|
|
16
|
+
if (!fs.existsSync(dirPath)) {
|
|
17
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
const typesGen = new TypesGen(contractMetadata);
|
|
20
|
+
const queryGen = new QueryGen(contractMetadata, typesGen);
|
|
21
|
+
const txGen = new TxGen(contractMetadata, typesGen);
|
|
22
|
+
const constructorTxGen = new ConstructorTxGen(contractMetadata, typesGen);
|
|
23
|
+
const constructorQueryGen = new ConstructorQueryGen(contractMetadata, typesGen);
|
|
24
|
+
const eventsGen = new EventsGen(contractMetadata, typesGen);
|
|
25
|
+
const indexGen = new IndexGen(contractMetadata);
|
|
26
|
+
fs.writeFileSync(typesFileName, await typesGen.generate(useSubPaths));
|
|
27
|
+
fs.writeFileSync(queryTypesFileName, await queryGen.generate(useSubPaths));
|
|
28
|
+
fs.writeFileSync(txTypesFileName, await txGen.generate(useSubPaths));
|
|
29
|
+
fs.writeFileSync(constructorQueryTypesFileName, await constructorQueryGen.generate(useSubPaths));
|
|
30
|
+
fs.writeFileSync(constructorTxTypesFileName, await constructorTxGen.generate(useSubPaths));
|
|
31
|
+
fs.writeFileSync(eventsTypesFile, await eventsGen.generate(useSubPaths));
|
|
32
|
+
fs.writeFileSync(indexTypesFileName, await indexGen.generate(useSubPaths));
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by dedot cli
|
|
2
|
+
|
|
3
|
+
{{{importTypes}}}
|
|
4
|
+
import { ContractQuery } from './query';
|
|
5
|
+
import { ContractTx } from './tx';
|
|
6
|
+
import { ConstructorQuery } from './constructor-query';
|
|
7
|
+
import { ConstructorTx } from './constructor-tx';
|
|
8
|
+
import { ContractEvents } from './events'
|
|
9
|
+
|
|
10
|
+
export interface {{{contractName}}}<Rv extends RpcVersion = RpcV2, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends GenericContractApi<Rv, ChainApi> {
|
|
11
|
+
query: ContractQuery<ChainApi[Rv]>;
|
|
12
|
+
tx: ContractTx<ChainApi[Rv]>;
|
|
13
|
+
constructorQuery: ConstructorQuery<ChainApi[Rv]>;
|
|
14
|
+
constructorTx: ConstructorTx<ChainApi[Rv]>;
|
|
15
|
+
events: ContractEvents<ChainApi[Rv]>;
|
|
16
|
+
}
|
|
@@ -2,7 +2,7 @@ export declare const WRAPPER_TYPE_REGEX: RegExp;
|
|
|
2
2
|
export declare const TUPLE_TYPE_REGEX: RegExp;
|
|
3
3
|
export declare const commentBlock: (...docs: (string | string[])[]) => string;
|
|
4
4
|
export declare const beautifySourceCode: (source: string) => Promise<string>;
|
|
5
|
-
export declare const compileTemplate: (
|
|
5
|
+
export declare const compileTemplate: (templateFile: string) => HandlebarsTemplateDelegate<any>;
|
|
6
6
|
/**
|
|
7
7
|
* Check if a word is TypeScript/JavaScript reserved
|
|
8
8
|
* @param word
|
|
@@ -7,7 +7,7 @@ export const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/;
|
|
|
7
7
|
export const TUPLE_TYPE_REGEX = /^\[(.*)]$/;
|
|
8
8
|
export const commentBlock = (...docs) => {
|
|
9
9
|
const flatLines = docs.flat();
|
|
10
|
-
if (flatLines.length === 0) {
|
|
10
|
+
if (flatLines.length === 0 || !flatLines.some((o) => !!o)) {
|
|
11
11
|
return '';
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -19,11 +19,11 @@ ${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(), '
|
|
22
|
+
const prettierOptions = await prettier.resolveConfig(path.resolve(currentDirname(), '../../../.prettierrc.cjs'));
|
|
23
23
|
return prettier.format(source, { parser: 'babel-ts', ...prettierOptions });
|
|
24
24
|
};
|
|
25
|
-
export const compileTemplate = (
|
|
26
|
-
const templateFilePath = path.resolve(currentDirname(),
|
|
25
|
+
export const compileTemplate = (templateFile) => {
|
|
26
|
+
const templateFilePath = path.resolve(currentDirname(), templateFile);
|
|
27
27
|
return handlebars.compile(fs.readFileSync(templateFilePath, 'utf8'));
|
|
28
28
|
};
|
|
29
29
|
// TODO add more reserved words
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IndexGen = void 0;
|
|
4
|
-
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
6
|
-
class IndexGen {
|
|
7
|
-
chain;
|
|
8
|
-
constructor(chain) {
|
|
9
|
-
this.chain = chain;
|
|
10
|
-
}
|
|
11
|
-
async generate() {
|
|
12
|
-
const interfaceName = (0, utils_1.stringPascalCase)(this.chain);
|
|
13
|
-
const template = (0, utils_js_1.compileTemplate)('index.hbs');
|
|
14
|
-
return (0, utils_js_1.beautifySourceCode)(template({ interfaceName }));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.IndexGen = IndexGen;
|
package/cjs/templates/consts.hbs
DELETED
package/cjs/templates/errors.hbs
DELETED
package/cjs/templates/events.hbs
DELETED
package/cjs/templates/index.hbs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Generated by @dedot/codegen
|
|
2
|
-
|
|
3
|
-
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
-
import { ChainConsts } from './consts';
|
|
5
|
-
import { ChainStorage } from './query';
|
|
6
|
-
import { ChainJsonRpcApis } from './json-rpc';
|
|
7
|
-
import { ChainErrors } from './errors';
|
|
8
|
-
import { ChainEvents } from './events';
|
|
9
|
-
import { RuntimeApis } from './runtime';
|
|
10
|
-
import { ChainTx } from './tx';
|
|
11
|
-
|
|
12
|
-
export * from './types';
|
|
13
|
-
|
|
14
|
-
export interface {{{interfaceName}}}Api extends GenericSubstrateApi {
|
|
15
|
-
rpc: ChainJsonRpcApis;
|
|
16
|
-
consts: ChainConsts;
|
|
17
|
-
query: ChainStorage;
|
|
18
|
-
errors: ChainErrors;
|
|
19
|
-
events: ChainEvents;
|
|
20
|
-
call: RuntimeApis;
|
|
21
|
-
tx: ChainTx;
|
|
22
|
-
}
|
package/cjs/templates/query.hbs
DELETED
package/cjs/templates/tx.hbs
DELETED
package/generator/IndexGen.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { stringPascalCase } from '@dedot/utils';
|
|
2
|
-
import { beautifySourceCode, compileTemplate } from './utils.js';
|
|
3
|
-
export class IndexGen {
|
|
4
|
-
chain;
|
|
5
|
-
constructor(chain) {
|
|
6
|
-
this.chain = chain;
|
|
7
|
-
}
|
|
8
|
-
async generate() {
|
|
9
|
-
const interfaceName = stringPascalCase(this.chain);
|
|
10
|
-
const template = compileTemplate('index.hbs');
|
|
11
|
-
return beautifySourceCode(template({ interfaceName }));
|
|
12
|
-
}
|
|
13
|
-
}
|
package/templates/consts.hbs
DELETED
package/templates/errors.hbs
DELETED
package/templates/events.hbs
DELETED
package/templates/index.hbs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Generated by @dedot/codegen
|
|
2
|
-
|
|
3
|
-
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
-
import { ChainConsts } from './consts';
|
|
5
|
-
import { ChainStorage } from './query';
|
|
6
|
-
import { ChainJsonRpcApis } from './json-rpc';
|
|
7
|
-
import { ChainErrors } from './errors';
|
|
8
|
-
import { ChainEvents } from './events';
|
|
9
|
-
import { RuntimeApis } from './runtime';
|
|
10
|
-
import { ChainTx } from './tx';
|
|
11
|
-
|
|
12
|
-
export * from './types';
|
|
13
|
-
|
|
14
|
-
export interface {{{interfaceName}}}Api extends GenericSubstrateApi {
|
|
15
|
-
rpc: ChainJsonRpcApis;
|
|
16
|
-
consts: ChainConsts;
|
|
17
|
-
query: ChainStorage;
|
|
18
|
-
errors: ChainErrors;
|
|
19
|
-
events: ChainEvents;
|
|
20
|
-
call: RuntimeApis;
|
|
21
|
-
tx: ChainTx;
|
|
22
|
-
}
|
package/templates/json-rpc.hbs
DELETED
package/templates/query.hbs
DELETED
package/templates/runtime.hbs
DELETED
package/templates/tx.hbs
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|