@dedot/codegen 0.0.1-alpha.4 → 0.0.1-alpha.40
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 +15 -15
- package/chaintypes/generator/ConstsGen.d.ts +4 -0
- package/{generator → chaintypes/generator}/ConstsGen.js +8 -9
- package/chaintypes/generator/ErrorsGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/ErrorsGen.js +11 -12
- package/chaintypes/generator/EventsGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/EventsGen.js +11 -12
- package/chaintypes/generator/IndexGen.d.ts +5 -0
- package/chaintypes/generator/IndexGen.js +17 -0
- package/chaintypes/generator/JsonRpcGen.d.ts +8 -0
- package/chaintypes/generator/JsonRpcGen.js +55 -0
- package/chaintypes/generator/QueryGen.d.ts +5 -0
- package/chaintypes/generator/QueryGen.js +63 -0
- package/chaintypes/generator/RuntimeApisGen.d.ts +9 -0
- package/chaintypes/generator/RuntimeApisGen.js +189 -0
- package/chaintypes/generator/TxGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/TxGen.js +18 -16
- package/chaintypes/generator/TypesGen.d.ts +11 -0
- package/chaintypes/generator/TypesGen.js +55 -0
- package/chaintypes/generator/index.d.ts +10 -0
- package/chaintypes/generator/index.js +10 -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/chaintypes/templates/types.hbs +5 -0
- package/cjs/{generator → chaintypes/generator}/ConstsGen.js +12 -13
- package/cjs/chaintypes/generator/ErrorsGen.js +40 -0
- package/cjs/{generator → chaintypes/generator}/EventsGen.js +17 -18
- package/cjs/chaintypes/generator/IndexGen.js +21 -0
- package/cjs/chaintypes/generator/JsonRpcGen.js +59 -0
- package/cjs/chaintypes/generator/QueryGen.js +67 -0
- package/cjs/chaintypes/generator/RuntimeApisGen.js +193 -0
- package/cjs/{generator → chaintypes/generator}/TxGen.js +27 -25
- package/cjs/chaintypes/generator/TypesGen.js +59 -0
- package/cjs/chaintypes/generator/index.js +26 -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/chaintypes/templates/types.hbs +5 -0
- package/cjs/{types.js → dirname.js} +3 -0
- package/cjs/index.js +4 -62
- package/cjs/{generator/TypesGen.js → shared/BaseTypesGen.js} +123 -177
- package/cjs/{generator → shared}/TypeImports.js +29 -3
- package/cjs/{generator → shared}/index.js +3 -10
- package/cjs/shared/known-codecs.js +170 -0
- package/cjs/typink/generator/ConstructorQueryGen.js +24 -0
- package/cjs/typink/generator/ConstructorTxGen.js +24 -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 +22 -0
- package/cjs/typink/index.js +37 -0
- package/cjs/typink/templates/constructor-query.hbs +7 -0
- package/cjs/typink/templates/constructor-tx.hbs +7 -0
- package/cjs/typink/templates/index.hbs +14 -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} +35 -11
- package/dirname.d.ts +1 -0
- package/dirname.js +6 -0
- package/index.d.ts +2 -4
- package/index.js +2 -48
- package/package.json +18 -19
- package/{generator/TypesGen.d.ts → shared/BaseTypesGen.d.ts} +13 -12
- package/{generator/TypesGen.js → shared/BaseTypesGen.js} +112 -166
- package/{generator → shared}/TypeImports.d.ts +12 -1
- package/{generator → shared}/TypeImports.js +29 -3
- package/shared/index.d.ts +3 -0
- package/shared/index.js +3 -0
- package/shared/known-codecs.d.ts +23 -0
- package/shared/known-codecs.js +139 -0
- 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/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 +6 -0
- package/typink/generator/index.js +6 -0
- package/typink/index.d.ts +2 -0
- package/typink/index.js +30 -0
- package/typink/templates/constructor-query.hbs +7 -0
- package/typink/templates/constructor-tx.hbs +7 -0
- package/typink/templates/index.hbs +14 -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} +6 -2
- package/{generator/utils.js → utils.js} +33 -9
- package/cjs/genSupportedChainTypes.js +0 -79
- package/cjs/generator/ErrorsGen.js +0 -41
- package/cjs/generator/IndexGen.js +0 -18
- package/cjs/generator/QueryGen.js +0 -59
- package/cjs/generator/RpcGen.js +0 -175
- package/cjs/generator/RuntimeApisGen.js +0 -120
- package/cjs/packageInfo.js +0 -5
- package/genSupportedChainTypes.d.ts +0 -1
- package/genSupportedChainTypes.js +0 -74
- package/generator/ConstsGen.d.ts +0 -4
- package/generator/ErrorsGen.d.ts +0 -5
- package/generator/EventsGen.d.ts +0 -5
- package/generator/IndexGen.d.ts +0 -6
- package/generator/IndexGen.js +0 -14
- package/generator/QueryGen.d.ts +0 -5
- package/generator/QueryGen.js +0 -55
- package/generator/RpcGen.d.ts +0 -10
- package/generator/RpcGen.js +0 -171
- package/generator/RuntimeApisGen.d.ts +0 -9
- package/generator/RuntimeApisGen.js +0 -116
- package/generator/TxGen.d.ts +0 -5
- package/generator/index.d.ts +0 -10
- package/generator/index.js +0 -10
- package/packageInfo.d.ts +0 -4
- package/packageInfo.js +0 -2
- package/types.d.ts +0 -6
- package/types.js +0 -1
- /package/{generator → chaintypes/generator}/ApiGen.js +0 -0
- /package/cjs/{generator → chaintypes/generator}/ApiGen.js +0 -0
package/generator/RpcGen.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { findAliasRpcSpec, findRpcSpec, isUnsubscribeMethod } from '@dedot/specs';
|
|
2
|
-
import { isNativeType } from '@dedot/utils';
|
|
3
|
-
import { ApiGen } from '../generator';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils';
|
|
5
|
-
const HIDDEN_RPCS = [
|
|
6
|
-
// Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
|
|
7
|
-
'rpc_methods',
|
|
8
|
-
];
|
|
9
|
-
export class RpcGen extends ApiGen {
|
|
10
|
-
typesGen;
|
|
11
|
-
rpcMethods;
|
|
12
|
-
constructor(typesGen, rpcMethods) {
|
|
13
|
-
super(typesGen);
|
|
14
|
-
this.typesGen = typesGen;
|
|
15
|
-
this.rpcMethods = rpcMethods;
|
|
16
|
-
HIDDEN_RPCS.filter((one) => !rpcMethods.includes(one)).forEach((one) => rpcMethods.push(one));
|
|
17
|
-
rpcMethods.sort();
|
|
18
|
-
}
|
|
19
|
-
generate() {
|
|
20
|
-
this.typesGen.clearCache();
|
|
21
|
-
this.typesGen.typeImports.addKnownType('GenericRpcCalls', 'Unsub', 'Callback', 'GenericRpcCall');
|
|
22
|
-
const specsByModule = this.rpcMethods
|
|
23
|
-
.filter((one) => !findAliasRpcSpec(one)) // we'll ignore alias rpc for now if defined in the specs! TODO should we generate alias rpc as well?
|
|
24
|
-
.filter((one) => !isUnsubscribeMethod(one)) // we'll ignore unsubscribe method as well
|
|
25
|
-
.map((one) => {
|
|
26
|
-
const spec = findRpcSpec(one);
|
|
27
|
-
if (spec) {
|
|
28
|
-
return spec;
|
|
29
|
-
}
|
|
30
|
-
const [module, ...methodParts] = one.split('_');
|
|
31
|
-
const method = methodParts.join('_');
|
|
32
|
-
return {
|
|
33
|
-
params: [],
|
|
34
|
-
type: 'GenericRpcCall',
|
|
35
|
-
module,
|
|
36
|
-
method,
|
|
37
|
-
};
|
|
38
|
-
})
|
|
39
|
-
.reduce((o, spec) => {
|
|
40
|
-
const { module, method } = spec;
|
|
41
|
-
// ignore if rpc name does not confront with the general convention
|
|
42
|
-
if (!module || !method) {
|
|
43
|
-
return o;
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
...o,
|
|
47
|
-
[module]: o[module] ? [...o[module], spec] : [spec],
|
|
48
|
-
};
|
|
49
|
-
}, {});
|
|
50
|
-
let rpcCallsOut = '';
|
|
51
|
-
Object.keys(specsByModule).forEach((module) => {
|
|
52
|
-
const specs = specsByModule[module];
|
|
53
|
-
// TODO add alias info to docs block!
|
|
54
|
-
rpcCallsOut += `${module}: {
|
|
55
|
-
${specs.map((spec) => this.#generateMethodDef(spec)).join(',\n')},
|
|
56
|
-
|
|
57
|
-
[method: string]: GenericRpcCall,
|
|
58
|
-
},`;
|
|
59
|
-
});
|
|
60
|
-
// TODO include & define external types
|
|
61
|
-
const importTypes = this.typesGen.typeImports.toImports();
|
|
62
|
-
const template = compileTemplate('rpc.hbs');
|
|
63
|
-
return beautifySourceCode(template({ importTypes, rpcCallsOut }));
|
|
64
|
-
}
|
|
65
|
-
#generateMethodDef(spec) {
|
|
66
|
-
const { name, type, module, method, docs = [], params, pubsub, deprecated } = spec;
|
|
67
|
-
const rpcName = name || `${module}_${method}`;
|
|
68
|
-
let defaultDocs = [`@rpcname: ${rpcName}`];
|
|
69
|
-
if (deprecated) {
|
|
70
|
-
defaultDocs.push(`@deprecated: ${deprecated}`);
|
|
71
|
-
}
|
|
72
|
-
if (type === 'GenericRpcCall' && params.length === 0) {
|
|
73
|
-
return `${commentBlock(defaultDocs)}${method}: GenericRpcCall`;
|
|
74
|
-
}
|
|
75
|
-
this.addTypeImport(type, false);
|
|
76
|
-
params.forEach(({ type, isScale }) => {
|
|
77
|
-
this.addTypeImport(type, !!isScale);
|
|
78
|
-
});
|
|
79
|
-
const typedParams = params.map((param) => ({
|
|
80
|
-
...param,
|
|
81
|
-
plainType: this.getGeneratedTypeName(param.type, !!param.isScale),
|
|
82
|
-
}));
|
|
83
|
-
const isSubscription = !!pubsub;
|
|
84
|
-
const paramsOut = typedParams.map(({ name, type, isOptional, isScale, plainType }) => `${name}${isOptional ? '?' : ''}: ${plainType}`);
|
|
85
|
-
const paramsDoc = typedParams.map(({ name, plainType }) => `@param {${plainType}} ${name}`);
|
|
86
|
-
const typeOut = this.getGeneratedTypeName(type, false);
|
|
87
|
-
if (isSubscription) {
|
|
88
|
-
defaultDocs.shift();
|
|
89
|
-
defaultDocs.unshift(`@pubsub: ${pubsub?.join(', ')}`);
|
|
90
|
-
paramsOut.push(`callback: Callback<${typeOut}>`);
|
|
91
|
-
return `${commentBlock(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return `${commentBlock(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// TODO check typeIn, typeOut if param type, or rpc type isScale
|
|
98
|
-
addTypeImport(type, toTypeIn = true) {
|
|
99
|
-
if (Array.isArray(type)) {
|
|
100
|
-
type.forEach((one) => this.addTypeImport(one, toTypeIn));
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
type = type.trim();
|
|
104
|
-
if (isNativeType(type)) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// Handle generic wrapper types
|
|
108
|
-
const matchArray = type.match(WRAPPER_TYPE_REGEX);
|
|
109
|
-
if (matchArray) {
|
|
110
|
-
const [_, $1, $2] = matchArray;
|
|
111
|
-
this.addTypeImport($1, toTypeIn);
|
|
112
|
-
if ($2.match(WRAPPER_TYPE_REGEX) || $2.match(TUPLE_TYPE_REGEX)) {
|
|
113
|
-
this.addTypeImport($2, toTypeIn);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
this.addTypeImport($2.split(','), toTypeIn);
|
|
117
|
-
}
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
// Check tuple type
|
|
121
|
-
if (type.match(TUPLE_TYPE_REGEX)) {
|
|
122
|
-
this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (type.includes(' | ')) {
|
|
126
|
-
this.addTypeImport(type.split(' | ').map((one) => one.trim()), toTypeIn);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
const codecType = this.#getCodecType(type, toTypeIn);
|
|
131
|
-
if (isNativeType(codecType))
|
|
132
|
-
return;
|
|
133
|
-
this.typesGen.typeImports.addCodecType(codecType);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
catch (e) { }
|
|
137
|
-
this.typesGen.addTypeImport(type);
|
|
138
|
-
}
|
|
139
|
-
getGeneratedTypeName(type, toTypeIn = true) {
|
|
140
|
-
try {
|
|
141
|
-
const matchArray = type.match(WRAPPER_TYPE_REGEX);
|
|
142
|
-
if (matchArray) {
|
|
143
|
-
const [_, $1, $2] = matchArray;
|
|
144
|
-
const wrapperTypeName = this.#getCodecType($1, toTypeIn);
|
|
145
|
-
if ($2.match(WRAPPER_TYPE_REGEX) || $2.match(TUPLE_TYPE_REGEX)) {
|
|
146
|
-
return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;
|
|
147
|
-
}
|
|
148
|
-
const innerTypeNames = $2
|
|
149
|
-
.split(',')
|
|
150
|
-
.map((one) => this.getGeneratedTypeName(one.trim(), toTypeIn))
|
|
151
|
-
.join(', ');
|
|
152
|
-
return `${wrapperTypeName}<${innerTypeNames}>`;
|
|
153
|
-
}
|
|
154
|
-
else if (type.match(TUPLE_TYPE_REGEX)) {
|
|
155
|
-
const innerTypeNames = type
|
|
156
|
-
.slice(1, -1)
|
|
157
|
-
.split(',')
|
|
158
|
-
.map((one) => this.getGeneratedTypeName(one.trim(), toTypeIn))
|
|
159
|
-
.join(', ');
|
|
160
|
-
return `[${innerTypeNames}]`;
|
|
161
|
-
}
|
|
162
|
-
return this.#getCodecType(type, toTypeIn);
|
|
163
|
-
}
|
|
164
|
-
catch (e) { }
|
|
165
|
-
return type;
|
|
166
|
-
}
|
|
167
|
-
#getCodecType(type, toTypeIn = true) {
|
|
168
|
-
const { typeIn, typeOut } = this.registry.findCodecType(type);
|
|
169
|
-
return toTypeIn ? typeIn : typeOut;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TypesGen } from './TypesGen';
|
|
2
|
-
import { RpcGen } from './RpcGen';
|
|
3
|
-
export declare class RuntimeApisGen extends RpcGen {
|
|
4
|
-
#private;
|
|
5
|
-
readonly typesGen: TypesGen;
|
|
6
|
-
readonly runtimeApis: [string, number][];
|
|
7
|
-
constructor(typesGen: TypesGen, runtimeApis: [string, number][]);
|
|
8
|
-
generate(): Promise<string>;
|
|
9
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { findRuntimeApiSpec } from '@dedot/specs';
|
|
2
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
3
|
-
import { calculateRuntimeApiHash, stringSnakeCase } from '@dedot/utils';
|
|
4
|
-
import { RpcGen } from './RpcGen';
|
|
5
|
-
import { stringCamelCase } from '@polkadot/util';
|
|
6
|
-
export class RuntimeApisGen extends RpcGen {
|
|
7
|
-
typesGen;
|
|
8
|
-
runtimeApis;
|
|
9
|
-
constructor(typesGen, runtimeApis) {
|
|
10
|
-
super(typesGen, []);
|
|
11
|
-
this.typesGen = typesGen;
|
|
12
|
-
this.runtimeApis = runtimeApis;
|
|
13
|
-
}
|
|
14
|
-
generate() {
|
|
15
|
-
this.typesGen.clearCache();
|
|
16
|
-
this.typesGen.typeImports.addKnownType('GenericRuntimeApis', 'GenericRuntimeApiMethod');
|
|
17
|
-
let runtimeCallsOut = '';
|
|
18
|
-
if (this.metadata.apis.length > 0) {
|
|
19
|
-
this.metadata.apis.forEach((runtimeApi) => {
|
|
20
|
-
const { name: runtimeApiName, methods } = runtimeApi;
|
|
21
|
-
runtimeCallsOut += commentBlock(`@runtimeapi: ${runtimeApiName} - ${calculateRuntimeApiHash(runtimeApiName)}`);
|
|
22
|
-
runtimeCallsOut += `${stringCamelCase(runtimeApiName)}: {
|
|
23
|
-
${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
|
|
24
|
-
|
|
25
|
-
${commentBlock('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
|
|
26
|
-
}`;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const specsByModule = this.#runtimeApisSpecsByModule();
|
|
31
|
-
Object.values(specsByModule).forEach((specs) => {
|
|
32
|
-
specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
|
|
33
|
-
runtimeCallsOut += commentBlock(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
|
|
34
|
-
runtimeCallsOut += `${stringCamelCase(runtimeApiName)}: {
|
|
35
|
-
${Object.keys(methods)
|
|
36
|
-
.map((methodName) => this.#generateMethodDefFromSpec({ ...methods[methodName], runtimeApiName, methodName }))
|
|
37
|
-
.join('\n')}
|
|
38
|
-
|
|
39
|
-
${commentBlock('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
|
|
40
|
-
}`;
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const importTypes = this.typesGen.typeImports.toImports();
|
|
45
|
-
const template = compileTemplate('runtime.hbs');
|
|
46
|
-
return beautifySourceCode(template({ importTypes, runtimeCallsOut }));
|
|
47
|
-
}
|
|
48
|
-
#isOptionalType(type) {
|
|
49
|
-
return type.startsWith('Option<') || type.endsWith('| undefined');
|
|
50
|
-
}
|
|
51
|
-
#isOptionalParam(params, type, idx) {
|
|
52
|
-
return this.#isOptionalType(type) && params.slice(idx + 1).every(({ type }) => this.#isOptionalType(type));
|
|
53
|
-
}
|
|
54
|
-
#generateMethodDefFromSpec(spec) {
|
|
55
|
-
const { docs = [], params, type, runtimeApiName, methodName } = spec;
|
|
56
|
-
const callName = `${runtimeApiName}_${stringSnakeCase(methodName)}`;
|
|
57
|
-
const defaultDocs = [`@callname: ${callName}`];
|
|
58
|
-
this.addTypeImport(type, false);
|
|
59
|
-
params.forEach(({ type }) => this.addTypeImport(type));
|
|
60
|
-
const typedParams = params.map((param, idx) => ({
|
|
61
|
-
...param,
|
|
62
|
-
isOptional: this.#isOptionalParam(params, param.type, idx),
|
|
63
|
-
plainType: this.getGeneratedTypeName(param.type),
|
|
64
|
-
}));
|
|
65
|
-
const paramsOut = typedParams
|
|
66
|
-
.map(({ name, isOptional, plainType }) => `${stringCamelCase(name)}${isOptional ? '?' : ''}: ${plainType}`)
|
|
67
|
-
.join(', ');
|
|
68
|
-
const typeOut = this.getGeneratedTypeName(type, false);
|
|
69
|
-
return `${commentBlock(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
70
|
-
}
|
|
71
|
-
#generateMethodDef(runtimeApiName, methodDef) {
|
|
72
|
-
const { name: methodName, inputs, output, docs } = methodDef;
|
|
73
|
-
const callName = `${runtimeApiName}_${stringSnakeCase(methodName)}`;
|
|
74
|
-
const defaultDocs = [`@callname: ${callName}`];
|
|
75
|
-
const typeOut = this.typesGen.generateType(output, 1, true);
|
|
76
|
-
this.addTypeImport(typeOut, false);
|
|
77
|
-
const typedInputs = inputs
|
|
78
|
-
.map((input, idx) => ({
|
|
79
|
-
...input,
|
|
80
|
-
type: this.typesGen.generateType(input.typeId, 1),
|
|
81
|
-
}))
|
|
82
|
-
.map((input, idx, inputs) => ({
|
|
83
|
-
...input,
|
|
84
|
-
isOptional: this.#isOptionalParam(inputs, input.type, idx),
|
|
85
|
-
}));
|
|
86
|
-
this.addTypeImport(typedInputs.map((t) => t.type));
|
|
87
|
-
const paramsOut = typedInputs
|
|
88
|
-
.map(({ name, type, isOptional }) => `${stringCamelCase(name)}${isOptional ? '?' : ''}: ${type}`)
|
|
89
|
-
.join(', ');
|
|
90
|
-
return `${commentBlock(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${stringCamelCase(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
91
|
-
}
|
|
92
|
-
#runtimeApisSpecsByModule() {
|
|
93
|
-
const specs = this.runtimeApis.map(([runtimeApiHash, version]) => {
|
|
94
|
-
const runtimeApiSpec = findRuntimeApiSpec(runtimeApiHash, version);
|
|
95
|
-
if (!runtimeApiSpec)
|
|
96
|
-
return;
|
|
97
|
-
return {
|
|
98
|
-
...runtimeApiSpec,
|
|
99
|
-
runtimeApiHash,
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
return specs.reduce((o, spec) => {
|
|
103
|
-
if (!spec) {
|
|
104
|
-
return o;
|
|
105
|
-
}
|
|
106
|
-
const { moduleName } = spec;
|
|
107
|
-
if (!moduleName) {
|
|
108
|
-
return o;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
...o,
|
|
112
|
-
[moduleName]: o[moduleName] ? [...o[moduleName], spec] : [spec],
|
|
113
|
-
};
|
|
114
|
-
}, {});
|
|
115
|
-
}
|
|
116
|
-
}
|
package/generator/TxGen.d.ts
DELETED
package/generator/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './RpcGen';
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
package/generator/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './RpcGen';
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
package/packageInfo.d.ts
DELETED
package/packageInfo.js
DELETED
package/types.d.ts
DELETED
package/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|