Sign In

@dedot/codegen

Package Overview
Dependencies
Maintainers
1
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dedot/codegen - npm Package Compare versions

Comparing version
0.0.1-next.0a597de3.0
to
0.0.1-next.16e37feb.8
+8
-8
cjs/generator/ConstsGen.js

@@ -6,5 +6,5 @@ "use strict";

const utils_1 = require("@dedot/utils");
const generator_1 = require("../generator");
const utils_2 = require("./utils");
class ConstsGen extends generator_1.ApiGen {
const index_js_1 = require("../generator/index.js");
const utils_js_1 = require("./utils.js");
class ConstsGen extends index_js_1.ApiGen {
generate() {

@@ -21,14 +21,14 @@ const { pallets } = this.metadata;

}));
defTypeOut += (0, utils_2.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
${typedConstants.map(({ name, type, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
${typedConstants.map(({ name, type, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
${(0, utils_2.commentBlock)('Generic pallet constant')}[name: string]: any,
${(0, utils_js_1.commentBlock)('Generic pallet constant')}[name: string]: any,
},`;
}
const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_2.compileTemplate)('consts.hbs');
return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
const template = (0, utils_js_1.compileTemplate)('consts.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
}
}
exports.ConstsGen = ConstsGen;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorsGen = void 0;
const ApiGen_1 = require("./ApiGen");
const utils_1 = require("./utils");
const ApiGen_js_1 = require("./ApiGen.js");
const utils_js_1 = require("./utils.js");
const util_1 = require("@polkadot/util");
const utils_2 = require("@dedot/utils");
class ErrorsGen extends ApiGen_1.ApiGen {
const utils_1 = require("@dedot/utils");
class ErrorsGen extends ApiGen_js_1.ApiGen {
generate() {

@@ -20,20 +20,20 @@ const { pallets } = this.metadata;

const errorDefs = this.#getErrorDefs(errorTypeId);
defTypeOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
${errorDefs
.map(({ name, docs }) => `${(0, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
.join(',\n')}
${(0, utils_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
${(0, utils_js_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
},`;
}
const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_1.compileTemplate)('errors.hbs');
return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
const template = (0, utils_js_1.compileTemplate)('errors.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
}
#getErrorDefs(errorTypeId) {
const def = this.metadata.types[errorTypeId];
(0, utils_2.assert)(def, `Error def not found for id ${errorTypeId}`);
(0, utils_1.assert)(def, `Error def not found for id ${errorTypeId}`);
const { tag, value } = def.type;
(0, utils_2.assert)(tag === 'Enum', `Invalid pallet error type!`);
(0, utils_1.assert)(tag === 'Enum', `Invalid pallet error type!`);
return value.members;

@@ -40,0 +40,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventsGen = void 0;
const ApiGen_1 = require("./ApiGen");
const utils_1 = require("./utils");
const ApiGen_js_1 = require("./ApiGen.js");
const utils_js_1 = require("./utils.js");
const util_1 = require("@polkadot/util");
const utils_2 = require("@dedot/utils");
class EventsGen extends ApiGen_1.ApiGen {
const utils_1 = require("@dedot/utils");
class EventsGen extends ApiGen_js_1.ApiGen {
generate() {

@@ -21,3 +21,3 @@ const { pallets } = this.metadata;

const flatMembers = eventDefs.every((d) => d.fields.length === 0);
defTypeOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {

@@ -36,17 +36,17 @@ ${eventDefs

})
.map(({ name, docs, fields, genericParts }) => `${(0, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
.map(({ name, docs, fields, genericParts }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
.join(',\n')}
${(0, utils_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
${(0, utils_js_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
},`;
}
const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_1.compileTemplate)('events.hbs');
return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
const template = (0, utils_js_1.compileTemplate)('events.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
}
#getEventDefs(typeId) {
const def = this.metadata.types[typeId];
(0, utils_2.assert)(def, `Event def not found for id ${typeId}`);
(0, utils_1.assert)(def, `Event def not found for id ${typeId}`);
const { tag, value } = def.type;
(0, utils_2.assert)(tag === 'Enum', 'Invalid pallet event type!');
(0, utils_1.assert)(tag === 'Enum', 'Invalid pallet event type!');
return value.members;

@@ -62,3 +62,3 @@ }

: `[${fields
.map(({ typeId, docs }) => `${(0, utils_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
.map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
.join(', ')}]`;

@@ -65,0 +65,0 @@ }

@@ -17,11 +17,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./TypesGen"), exports);
__exportStar(require("./ApiGen"), exports);
__exportStar(require("./ConstsGen"), exports);
__exportStar(require("./QueryGen"), exports);
__exportStar(require("./RpcGen"), exports);
__exportStar(require("./IndexGen"), exports);
__exportStar(require("./ErrorsGen"), exports);
__exportStar(require("./EventsGen"), exports);
__exportStar(require("./TxGen"), exports);
__exportStar(require("./RuntimeApisGen"), exports);
__exportStar(require("./TypesGen.js"), exports);
__exportStar(require("./ApiGen.js"), exports);
__exportStar(require("./ConstsGen.js"), exports);
__exportStar(require("./QueryGen.js"), exports);
__exportStar(require("./RpcGen.js"), exports);
__exportStar(require("./IndexGen.js"), exports);
__exportStar(require("./ErrorsGen.js"), exports);
__exportStar(require("./EventsGen.js"), exports);
__exportStar(require("./TxGen.js"), exports);
__exportStar(require("./RuntimeApisGen.js"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexGen = void 0;
const utils_1 = require("./utils");
const utils_js_1 = require("./utils.js");
const util_1 = require("@polkadot/util");

@@ -14,6 +14,6 @@ class IndexGen {

const interfaceName = (0, util_1.stringPascalCase)(chain);
const template = (0, utils_1.compileTemplate)('index.hbs');
return (0, utils_1.beautifySourceCode)(template({ interfaceName }));
const template = (0, utils_js_1.compileTemplate)('index.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ interfaceName }));
}
}
exports.IndexGen = IndexGen;

@@ -6,5 +6,5 @@ "use strict";

const utils_1 = require("@dedot/utils");
const generator_1 = require("../generator");
const utils_2 = require("./utils");
class QueryGen extends generator_1.ApiGen {
const index_js_1 = require("../generator/index.js");
const utils_js_1 = require("./utils.js");
class QueryGen extends index_js_1.ApiGen {
generate() {

@@ -20,13 +20,13 @@ const { pallets } = this.metadata;

const queries = storage.entries.map((one) => this.#generateEntry(one));
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
defTypeOut += (0, utils_2.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
${queryDefs.join(',\n')}
${(0, utils_2.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
},`;
}
const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_2.compileTemplate)('query.hbs');
return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
const template = (0, utils_js_1.compileTemplate)('query.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
}

@@ -33,0 +33,0 @@ #generateEntry(entry) {

@@ -6,5 +6,5 @@ "use strict";

const utils_1 = require("@dedot/utils");
const generator_1 = require("../generator");
const utils_2 = require("./utils");
const known_codecs_1 = require("./known-codecs");
const index_js_1 = require("../generator/index.js");
const utils_js_1 = require("./utils.js");
const known_codecs_js_1 = require("./known-codecs.js");
const HIDDEN_RPCS = [

@@ -14,3 +14,3 @@ // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158

];
class RpcGen extends generator_1.ApiGen {
class RpcGen extends index_js_1.ApiGen {
typesGen;

@@ -68,4 +68,4 @@ rpcMethods;

const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_2.compileTemplate)('rpc.hbs');
return (0, utils_2.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
const template = (0, utils_js_1.compileTemplate)('rpc.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
}

@@ -80,3 +80,3 @@ #generateMethodDef(spec) {

if (type === 'GenericRpcCall' && params.length === 0) {
return `${(0, utils_2.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
return `${(0, utils_js_1.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
}

@@ -99,6 +99,6 @@ this.addTypeImport(type, false);

paramsOut.push(`callback: Callback<${typeOut}>`);
return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
}
else {
return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
}

@@ -117,7 +117,7 @@ }

// Handle generic wrapper types
const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
if (matchArray) {
const [_, $1, $2] = matchArray;
this.addTypeImport($1, toTypeIn);
if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
this.addTypeImport($2, toTypeIn);

@@ -131,3 +131,3 @@ }

// Check tuple type
if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);

@@ -152,7 +152,7 @@ return;

try {
const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
if (matchArray) {
const [_, $1, $2] = matchArray;
const wrapperTypeName = this.#getCodecType($1, toTypeIn);
if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;

@@ -166,3 +166,3 @@ }

}
else if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
else if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
const innerTypeNames = type

@@ -181,3 +181,3 @@ .slice(1, -1)

#getCodecType(type, toTypeIn = true) {
const { typeIn, typeOut } = (0, known_codecs_1.findKnownCodecType)(type);
const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type);
return toTypeIn ? typeIn : typeOut;

@@ -184,0 +184,0 @@ }

@@ -5,7 +5,7 @@ "use strict";

const specs_1 = require("@dedot/specs");
const utils_1 = require("./utils");
const utils_2 = require("@dedot/utils");
const RpcGen_1 = require("./RpcGen");
const utils_js_1 = require("./utils.js");
const utils_1 = require("@dedot/utils");
const RpcGen_js_1 = require("./RpcGen.js");
const util_1 = require("@polkadot/util");
class RuntimeApisGen extends RpcGen_1.RpcGen {
class RuntimeApisGen extends RpcGen_js_1.RpcGen {
typesGen;

@@ -25,7 +25,7 @@ runtimeApis;

const { name: runtimeApiName, methods } = runtimeApi;
runtimeCallsOut += (0, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_2.calculateRuntimeApiHash)(runtimeApiName)}`);
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_1.calculateRuntimeApiHash)(runtimeApiName)}`);
runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {
${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
${(0, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
}`;

@@ -37,3 +37,3 @@ });

specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
runtimeCallsOut += (0, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {

@@ -48,3 +48,3 @@ ${Object.keys(methods)

${(0, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
}`;

@@ -54,4 +54,4 @@ });

const importTypes = this.typesGen.typeImports.toImports();
const template = (0, utils_1.compileTemplate)('runtime.hbs');
return (0, utils_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
const template = (0, utils_js_1.compileTemplate)('runtime.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
}

@@ -66,3 +66,3 @@ #isOptionalType(type) {

const { docs = [], params, type, runtimeApiName, methodName } = spec;
const callName = `${runtimeApiName}_${(0, utils_2.stringSnakeCase)(methodName)}`;
const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
const defaultDocs = [`@callname: ${callName}`];

@@ -80,7 +80,7 @@ this.addTypeImport(type, false);

const typeOut = this.getGeneratedTypeName(type, false);
return `${(0, utils_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
}
#generateMethodDef(runtimeApiName, methodDef) {
const { name: methodName, inputs, output, docs } = methodDef;
const callName = `${runtimeApiName}_${(0, utils_2.stringSnakeCase)(methodName)}`;
const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
const defaultDocs = [`@callname: ${callName}`];

@@ -102,3 +102,3 @@ const typeOut = this.typesGen.generateType(output, 1, true);

.join(', ');
return `${(0, utils_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, util_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, util_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
}

@@ -123,3 +123,3 @@ #targetRuntimeApiSpecs() {

#findRuntimeApiSpec = (runtimeApiHash, version) => {
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_2.calculateRuntimeApiHash)(one) === runtimeApiHash);
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calculateRuntimeApiHash)(one) === runtimeApiHash);
return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);

@@ -126,0 +126,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TxGen = void 0;
const generator_1 = require("../generator");
const index_js_1 = require("../generator/index.js");
const util_1 = require("@polkadot/util");
const utils_1 = require("./utils");
class TxGen extends generator_1.ApiGen {
const utils_js_1 = require("./utils.js");
class TxGen extends index_js_1.ApiGen {
generate() {

@@ -44,9 +44,9 @@ const { pallets, types } = this.metadata;

});
txDefsOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
txDefsOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
txDefsOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
${typedTxs
.map(({ functionName, params, docs, callInput }) => `${(0, utils_1.commentBlock)(docs, '\n', params.map((p) => `@param {${p.type}} ${p.normalizedName} ${p.docs}`))}${functionName}: GenericTxCall<(${params.map((p) => `${p.normalizedName}: ${p.type}`).join(', ')}) => ChainSubmittableExtrinsic<${callInput}>>`)
.map(({ functionName, params, docs, callInput }) => `${(0, utils_js_1.commentBlock)(docs, '\n', params.map((p) => `@param {${p.type}} ${p.normalizedName} ${p.docs}`))}${functionName}: GenericTxCall<(${params.map((p) => `${p.normalizedName}: ${p.type}`).join(', ')}) => ChainSubmittableExtrinsic<${callInput}>>`)
.join(',\n')}
${(0, utils_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<TxCall>,
${(0, utils_js_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<TxCall>,
},`;

@@ -63,8 +63,8 @@ }

`;
const template = (0, utils_1.compileTemplate)('tx.hbs');
return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
const template = (0, utils_js_1.compileTemplate)('tx.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
}
#normalizeParamName(name) {
name = (0, util_1.stringCamelCase)(name);
return (0, utils_1.isReservedWord)(name) ? `${name}_` : name;
return (0, utils_js_1.isReservedWord)(name) ? `${name}_` : name;
}

@@ -71,0 +71,0 @@ #generateCallInput(palletName, callName, params) {

@@ -7,6 +7,6 @@ "use strict";

const utils_1 = require("@dedot/utils");
const utils_2 = require("./utils");
const known_types_1 = require("./known-types");
const TypeImports_1 = require("./TypeImports");
const known_codecs_1 = require("./known-codecs");
const utils_js_1 = require("./utils.js");
const known_types_js_1 = require("./known-types.js");
const TypeImports_js_1 = require("./TypeImports.js");
const known_codecs_js_1 = require("./known-codecs.js");
// Skip generate types for these

@@ -47,3 +47,3 @@ // as we do have native types for them

this.includedTypes = this.#includedTypes();
this.typeImports = new TypeImports_1.TypeImports();
this.typeImports = new TypeImports_js_1.TypeImports();
}

@@ -56,3 +56,3 @@ generate() {

.forEach(({ name, nameOut, id, docs }) => {
defTypeOut += `${(0, utils_2.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
defTypeOut += `${(0, utils_js_1.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
if (this.#shouldGenerateTypeIn(id)) {

@@ -63,4 +63,4 @@ defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;

const importTypes = this.typeImports.toImports('./types');
const template = (0, utils_2.compileTemplate)('types.hbs');
return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
const template = (0, utils_js_1.compileTemplate)('types.hbs');
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
}

@@ -110,3 +110,3 @@ typeCache = {};

case 'Primitive':
const $codec = (0, known_codecs_1.findKnownCodec)(value.kind);
const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind);
if ($codec.nativeType) {

@@ -159,3 +159,3 @@ return $codec.nativeType;

else if (members.every((x) => x.fields.length === 0)) {
return members.map(({ name, docs }) => `${(0, utils_2.commentBlock)(docs)}'${(0, util_1.stringPascalCase)(name)}'`).join(' | ');
return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0, util_1.stringPascalCase)(name)}'`).join(' | ');
}

@@ -173,3 +173,3 @@ else {

: `[${fields
.map(({ typeId, docs }) => `${(0, utils_2.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
.map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
.join(', ')}]`;

@@ -189,3 +189,3 @@ membersType.push([keyName, valueType, docs]);

}))
.map(({ tag, value, docs }) => `${(0, utils_2.commentBlock)(docs)}{ ${tag}${value} }`)
.map(({ tag, value, docs }) => `${(0, utils_js_1.commentBlock)(docs)}{ ${tag}${value} }`)
.join(' | ');

@@ -237,3 +237,3 @@ }

return `{${props
.map(({ name, type, optional, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
.map(({ name, type, optional, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
.join(',\n')}}`;

@@ -279,4 +279,4 @@ }

let name, nameOut;
if ((0, known_codecs_1.isKnownCodecType)(joinedPath)) {
const codecType = (0, known_codecs_1.findKnownCodecType)(path.at(-1));
if ((0, known_codecs_js_1.isKnownCodecType)(joinedPath)) {
const codecType = (0, known_codecs_js_1.findKnownCodecType)(path.at(-1));
name = codecType.typeIn;

@@ -439,3 +439,3 @@ nameOut = codecType.typeOut;

}
if (known_types_1.knownTypes.includes(typeName)) {
if (known_types_js_1.knownTypes.includes(typeName)) {
this.typeImports.addKnownType(typeName);

@@ -442,0 +442,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
const index_js_1 = require("./index.js");
const static_substrate_1 = require("@polkadot/types-support/metadata/static-substrate");

@@ -65,3 +65,3 @@ const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex"));

console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
await (0, index_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
await (0, index_js_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
}

@@ -72,3 +72,3 @@ else if (metadataHex && rpcMethods) {

const runtimeVersion = getRuntimeVersion(metadata);
await (0, index_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
await (0, index_js_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
}

@@ -75,0 +75,0 @@ }

@@ -30,3 +30,3 @@ "use strict";

const path = __importStar(require("path"));
const generator_1 = require("./generator");
const index_js_1 = require("./generator/index.js");
const util_1 = require("@polkadot/util");

@@ -58,11 +58,11 @@ async function generateTypesFromChain(network, endpoint, outDir) {

}
const typesGen = new generator_1.TypesGen(metadata);
const constsGen = new generator_1.ConstsGen(typesGen);
const queryGen = new generator_1.QueryGen(typesGen);
const rpcGen = new generator_1.RpcGen(typesGen, rpcMethods);
const indexGen = new generator_1.IndexGen(network);
const errorsGen = new generator_1.ErrorsGen(typesGen);
const eventsGen = new generator_1.EventsGen(typesGen);
const runtimeApisGen = new generator_1.RuntimeApisGen(typesGen, runtimeApis);
const txGen = new generator_1.TxGen(typesGen);
const typesGen = new index_js_1.TypesGen(metadata);
const constsGen = new index_js_1.ConstsGen(typesGen);
const queryGen = new index_js_1.QueryGen(typesGen);
const rpcGen = new index_js_1.RpcGen(typesGen, rpcMethods);
const indexGen = new index_js_1.IndexGen(network);
const errorsGen = new index_js_1.ErrorsGen(typesGen);
const eventsGen = new index_js_1.EventsGen(typesGen);
const runtimeApisGen = new index_js_1.RuntimeApisGen(typesGen, runtimeApis);
const txGen = new index_js_1.TxGen(typesGen);
fs.writeFileSync(defTypesFileName, await typesGen.generate());

@@ -69,0 +69,0 @@ fs.writeFileSync(errorsFileName, await errorsGen.generate());

@@ -5,2 +5,2 @@ "use strict";

exports.packageInfo = void 0;
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.27' };
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };

@@ -1,2 +0,2 @@

import { TypesGen } from '../generator';
import { TypesGen } from '../generator/index.js';
export declare abstract class ApiGen {

@@ -3,0 +3,0 @@ readonly typesGen: TypesGen;

@@ -1,4 +0,4 @@

import { ApiGen } from '../generator';
import { ApiGen } from '../generator/index.js';
export declare class ConstsGen extends ApiGen {
generate(): Promise<string>;
}
import { stringLowerFirst } from '@polkadot/util';
import { normalizeName } from '@dedot/utils';
import { ApiGen } from '../generator';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { ApiGen } from '../generator/index.js';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
export class ConstsGen extends ApiGen {

@@ -6,0 +6,0 @@ generate() {

@@ -1,2 +0,2 @@

import { ApiGen } from './ApiGen';
import { ApiGen } from './ApiGen.js';
export declare class ErrorsGen extends ApiGen {

@@ -3,0 +3,0 @@ #private;

@@ -1,3 +0,3 @@

import { ApiGen } from './ApiGen';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { ApiGen } from './ApiGen.js';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
import { stringCamelCase, stringPascalCase } from '@polkadot/util';

@@ -4,0 +4,0 @@ import { assert } from '@dedot/utils';

@@ -1,2 +0,2 @@

import { ApiGen } from './ApiGen';
import { ApiGen } from './ApiGen.js';
export declare class EventsGen extends ApiGen {

@@ -3,0 +3,0 @@ #private;

@@ -1,3 +0,3 @@

import { ApiGen } from './ApiGen';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { ApiGen } from './ApiGen.js';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
import { stringCamelCase, stringPascalCase } from '@polkadot/util';

@@ -4,0 +4,0 @@ import { assert } from '@dedot/utils';

@@ -1,10 +0,10 @@

export * from './TypesGen';
export * from './ApiGen';
export * from './ConstsGen';
export * from './QueryGen';
export * from './RpcGen';
export * from './IndexGen';
export * from './ErrorsGen';
export * from './EventsGen';
export * from './TxGen';
export * from './RuntimeApisGen';
export * from './TypesGen.js';
export * from './ApiGen.js';
export * from './ConstsGen.js';
export * from './QueryGen.js';
export * from './RpcGen.js';
export * from './IndexGen.js';
export * from './ErrorsGen.js';
export * from './EventsGen.js';
export * from './TxGen.js';
export * from './RuntimeApisGen.js';

@@ -1,10 +0,10 @@

export * from './TypesGen';
export * from './ApiGen';
export * from './ConstsGen';
export * from './QueryGen';
export * from './RpcGen';
export * from './IndexGen';
export * from './ErrorsGen';
export * from './EventsGen';
export * from './TxGen';
export * from './RuntimeApisGen';
export * from './TypesGen.js';
export * from './ApiGen.js';
export * from './ConstsGen.js';
export * from './QueryGen.js';
export * from './RpcGen.js';
export * from './IndexGen.js';
export * from './ErrorsGen.js';
export * from './EventsGen.js';
export * from './TxGen.js';
export * from './RuntimeApisGen.js';

@@ -1,2 +0,2 @@

import { NetworkInfo } from '../types';
import { NetworkInfo } from '../types.js';
export declare class IndexGen {

@@ -3,0 +3,0 @@ readonly networkInfo: NetworkInfo;

@@ -1,2 +0,2 @@

import { beautifySourceCode, compileTemplate } from './utils';
import { beautifySourceCode, compileTemplate } from './utils.js';
import { stringPascalCase } from '@polkadot/util';

@@ -3,0 +3,0 @@ export class IndexGen {

@@ -1,2 +0,2 @@

import { ApiGen } from '../generator';
import { ApiGen } from '../generator/index.js';
export declare class QueryGen extends ApiGen {

@@ -3,0 +3,0 @@ #private;

import { stringLowerFirst } from '@polkadot/util';
import { normalizeName } from '@dedot/utils';
import { ApiGen } from '../generator';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { ApiGen } from '../generator/index.js';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
export class QueryGen extends ApiGen {

@@ -6,0 +6,0 @@ generate() {

@@ -1,2 +0,2 @@

import { ApiGen, TypesGen } from '../generator';
import { ApiGen, TypesGen } from '../generator/index.js';
export declare class RpcGen extends ApiGen {

@@ -3,0 +3,0 @@ #private;

import { findAliasRpcSpec, findRpcSpec, isUnsubscribeMethod } from '@dedot/specs';
import { isNativeType } from '@dedot/utils';
import { ApiGen } from '../generator';
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils';
import { findKnownCodecType } from './known-codecs';
import { ApiGen } from '../generator/index.js';
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils.js';
import { findKnownCodecType } from './known-codecs.js';
const HIDDEN_RPCS = [

@@ -7,0 +7,0 @@ // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158

@@ -1,3 +0,3 @@

import { TypesGen } from './TypesGen';
import { RpcGen } from './RpcGen';
import { TypesGen } from './TypesGen.js';
import { RpcGen } from './RpcGen.js';
export declare class RuntimeApisGen extends RpcGen {

@@ -4,0 +4,0 @@ #private;

import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
import { calculateRuntimeApiHash, stringSnakeCase } from '@dedot/utils';
import { RpcGen } from './RpcGen';
import { RpcGen } from './RpcGen.js';
import { stringCamelCase } from '@polkadot/util';

@@ -6,0 +6,0 @@ export class RuntimeApisGen extends RpcGen {

@@ -1,2 +0,2 @@

import { ApiGen } from '../generator';
import { ApiGen } from '../generator/index.js';
export declare class TxGen extends ApiGen {

@@ -3,0 +3,0 @@ #private;

@@ -1,4 +0,4 @@

import { ApiGen } from '../generator';
import { ApiGen } from '../generator/index.js';
import { stringCamelCase, stringPascalCase } from '@polkadot/util';
import { beautifySourceCode, commentBlock, compileTemplate, isReservedWord } from './utils';
import { beautifySourceCode, commentBlock, compileTemplate, isReservedWord } from './utils.js';
export class TxGen extends ApiGen {

@@ -5,0 +5,0 @@ generate() {

import { PortableRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs';
import { TypeImports } from './TypeImports';
import { TypeImports } from './TypeImports.js';
interface NamedType extends PortableType {

@@ -4,0 +4,0 @@ name: string;

import { stringPascalCase } from '@polkadot/util';
import { PortableRegistry } from '@dedot/codecs';
import { isNativeType, normalizeName } from '@dedot/utils';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
import { knownTypes } from './known-types';
import { TypeImports } from './TypeImports';
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs';
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
import { knownTypes } from './known-types.js';
import { TypeImports } from './TypeImports.js';
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs.js';
// Skip generate types for these

@@ -9,0 +9,0 @@ // as we do have native types for them

@@ -1,2 +0,2 @@

import { generateTypes, generateTypesFromChain } from './index';
import { generateTypes, generateTypesFromChain } from './index.js';
import { rpc } from '@polkadot/types-support/metadata/static-substrate';

@@ -3,0 +3,0 @@ import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex';

import { MetadataLatest } from '@dedot/codecs';
import { NetworkInfo } from './types';
import { NetworkInfo } from './types.js';
export declare function generateTypesFromChain(network: NetworkInfo, endpoint: string, outDir: string): Promise<void>;
export declare function generateTypes(network: NetworkInfo, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
import { Dedot } from 'dedot';
import * as fs from 'fs';
import * as path from 'path';
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator';
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator/index.js';
import { stringCamelCase } from '@polkadot/util';

@@ -6,0 +6,0 @@ export async function generateTypesFromChain(network, endpoint, outDir) {

{
"name": "@dedot/codegen",
"version": "0.0.1-next.0a597de3.0+0a597de",
"version": "0.0.1-next.16e37feb.8+16e37fe",
"description": "Generate types",

@@ -21,8 +21,8 @@ "author": "Thang X. Vu <thang@coongcrafts.io>",

"dependencies": {
"@dedot/codecs": "0.0.1-next.0a597de3.0+0a597de",
"@dedot/shape": "0.0.1-next.0a597de3.0+0a597de",
"@dedot/specs": "0.0.1-next.0a597de3.0+0a597de",
"@dedot/utils": "0.0.1-next.0a597de3.0+0a597de",
"@dedot/codecs": "0.0.1-next.16e37feb.8+16e37fe",
"@dedot/shape": "0.0.1-next.16e37feb.8+16e37fe",
"@dedot/specs": "0.0.1-next.16e37feb.8+16e37fe",
"@dedot/utils": "0.0.1-next.16e37feb.8+16e37fe",
"@polkadot/util": "^12.6.2",
"dedot": "0.0.1-next.0a597de3.0+0a597de",
"dedot": "0.0.1-next.16e37feb.8+16e37fe",
"handlebars": "^4.7.8",

@@ -36,3 +36,3 @@ "prettier": "^3.0.3"

"license": "Apache-2.0",
"gitHead": "0a597de3c59c70bf39a56e1569e76b61dce9af8f",
"gitHead": "16e37feb35200c80b3ffcba5791154050da36443",
"module": "./index.js",

@@ -39,0 +39,0 @@ "types": "./index.d.ts",

// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.27' };
export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };