@dedot/codegen
Advanced tools
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isKnownCodecType = exports.findKnownWrapperCodec = exports.findKnownCodec = exports.findKnownCodecType = exports.looseTypeCodecs = exports.normalizeCodecName = void 0; | ||
| const $ = __importStar(require("@dedot/shape")); | ||
| const Codecs = __importStar(require("@dedot/codecs")); | ||
| const codecs_1 = require("@dedot/codecs"); | ||
| const utils_1 = require("@dedot/utils"); | ||
| const normalizeCodecName = (name) => { | ||
| return name.startsWith('$') ? name : `$${name}`; | ||
| }; | ||
| exports.normalizeCodecName = normalizeCodecName; | ||
| // Known paths for codecs (primitives) that are shared between | ||
| // different substrate-based blockchains | ||
| const KNOWN_PATHS = [ | ||
| 'sp_core::crypto::AccountId32', | ||
| 'sp_runtime::generic::era::Era', | ||
| 'sp_runtime::multiaddress::MultiAddress', | ||
| /^sp_runtime::DispatchError$/, | ||
| 'sp_runtime::ModuleError', | ||
| 'sp_runtime::TokenError', | ||
| 'sp_arithmetic::ArithmeticError', | ||
| 'sp_runtime::TransactionalError', | ||
| 'frame_support::dispatch::DispatchInfo', | ||
| 'frame_system::Phase', | ||
| 'sp_version::RuntimeVersion', | ||
| 'fp_account::AccountId20', | ||
| 'account::AccountId20', | ||
| 'polkadot_runtime_common::claims::EthereumAddress', | ||
| 'pallet_identity::types::Data', | ||
| 'sp_runtime::generic::digest::Digest', | ||
| 'sp_runtime::generic::digest::DigestItem', | ||
| 'sp_runtime::generic::header::Header', | ||
| 'sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic', | ||
| /^primitive_types::\w+$/, | ||
| /^sp_arithmetic::per_things::\w+$/, | ||
| /^sp_arithmetic::fixed_point::\w+$/, | ||
| ]; | ||
| const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/; | ||
| const TUPLE_TYPE_REGEX = /^\[(.*)]$/; | ||
| const KNOWN_WRAPPER_TYPES = ['Option', 'Vec', 'Result', 'Array']; | ||
| /** | ||
| * Collection of codec types with loose input types | ||
| * | ||
| * Loose codecs are codecs with different typeIn & typeOut, | ||
| * E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32` | ||
| * | ||
| * This registry keep track the list of codecs which follow this convention | ||
| */ | ||
| exports.looseTypeCodecs = { | ||
| $AccountId20: codecs_1.$AccountId20, | ||
| $EthereumAddress: codecs_1.$EthereumAddress, | ||
| $AccountId32: codecs_1.$AccountId32, | ||
| $ConsensusEngineId: codecs_1.$ConsensusEngineId, | ||
| $StorageKey: codecs_1.$StorageKey, | ||
| $StorageData: codecs_1.$StorageData, | ||
| $PrefixedStorageKey: codecs_1.$PrefixedStorageKey, | ||
| $Bytes: codecs_1.$Bytes, | ||
| $RawBytes: codecs_1.$RawBytes, | ||
| $MultiAddress: codecs_1.$MultiAddress, | ||
| $OpaqueExtrinsic: codecs_1.$OpaqueExtrinsic, | ||
| $UncheckedExtrinsic: codecs_1.$UncheckedExtrinsic, | ||
| $Era: codecs_1.$Era, | ||
| }; | ||
| function findKnownCodecType(name) { | ||
| const normalizedName = (0, exports.normalizeCodecName)(name); | ||
| const $knownCodec = exports.looseTypeCodecs[normalizedName]; | ||
| if ($knownCodec) { | ||
| return { | ||
| name: normalizedName, | ||
| $codec: $knownCodec, | ||
| typeIn: `${name}Like`, | ||
| typeOut: name, | ||
| }; | ||
| } | ||
| const $codec = findKnownCodec(name); | ||
| if ($codec.nativeType && $[name]) { | ||
| return { | ||
| name: normalizedName, | ||
| $codec, | ||
| typeIn: $codec.nativeType, | ||
| typeOut: $codec.nativeType, | ||
| }; | ||
| } | ||
| return { | ||
| name: normalizedName, | ||
| $codec, | ||
| typeIn: name, | ||
| typeOut: name, | ||
| }; | ||
| } | ||
| exports.findKnownCodecType = findKnownCodecType; | ||
| function findKnownCodec(typeName) { | ||
| // @ts-ignore | ||
| const $codec = findKnownWrapperCodec(typeName) || Codecs[(0, exports.normalizeCodecName)(typeName)] || $[typeName]; | ||
| (0, utils_1.assert)($codec, `Known codec not found - ${typeName}`); | ||
| return $codec; | ||
| } | ||
| exports.findKnownCodec = findKnownCodec; | ||
| function findKnownWrapperCodec(typeName) { | ||
| const matchNames = typeName.match(WRAPPER_TYPE_REGEX); | ||
| if (matchNames) { | ||
| const [_, wrapper, inner] = matchNames; | ||
| if (KNOWN_WRAPPER_TYPES.includes(wrapper)) { | ||
| // @ts-ignore | ||
| const $Wrapper = $[wrapper]; | ||
| if (inner.match(TUPLE_TYPE_REGEX) || inner.match(WRAPPER_TYPE_REGEX)) { | ||
| return $Wrapper(findKnownWrapperCodec(inner)); | ||
| } | ||
| const $inners = inner.split(',').map((one) => findKnownCodec(one.trim())); | ||
| return $Wrapper(...$inners); | ||
| } | ||
| throw new Error(`Unknown wrapper type ${wrapper} from ${typeName}`); | ||
| } | ||
| else if (typeName.match(TUPLE_TYPE_REGEX)) { | ||
| const $inner = typeName | ||
| .slice(1, -1) | ||
| .split(',') | ||
| .filter((x) => x) | ||
| .map((one) => findKnownCodec(one.trim())); | ||
| return $.Tuple(...$inner); | ||
| } | ||
| } | ||
| exports.findKnownWrapperCodec = findKnownWrapperCodec; | ||
| function isKnownCodecType(path) { | ||
| const joinedPath = Array.isArray(path) ? path.join('::') : path; | ||
| return KNOWN_PATHS.some((one) => joinedPath.match(one)); | ||
| } | ||
| exports.isKnownCodecType = isKnownCodecType; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.knownTypes = void 0; | ||
| /** | ||
| * Known type names registered in @dedot/types | ||
| * Since TS interfaces are trim-off when compiling, | ||
| * So we need to register them explicitly here for RPC codegen process | ||
| */ | ||
| exports.knownTypes = [ | ||
| 'ExtrinsicOrHash', | ||
| 'EpochAuthorship', | ||
| 'BlockStats', | ||
| 'Prevotes', | ||
| 'Precommits', | ||
| 'RoundState', | ||
| 'ReportedRoundStates', | ||
| 'JustificationNotification', | ||
| 'EncodedFinalityProofs', | ||
| 'LeavesProof', | ||
| 'StorageKind', | ||
| 'RpcMethods', | ||
| 'ReadProof', | ||
| 'StorageChangeSet', | ||
| 'TraceBlockResponse', | ||
| 'MigrationStatusResult', | ||
| 'ChainType', | ||
| 'ChainProperties', | ||
| 'Health', | ||
| 'SyncState', | ||
| 'PeerInfo', | ||
| 'NodeRole', | ||
| 'NetworkState', | ||
| ]; |
| import * as $ from '@dedot/shape'; | ||
| import { AnyShape } from '@dedot/shape'; | ||
| export type CodecName = `$${string}`; | ||
| export interface CodecType { | ||
| name: CodecName; | ||
| $codec: AnyShape; | ||
| typeIn: string; | ||
| typeOut: string; | ||
| } | ||
| export declare const normalizeCodecName: (name: string | CodecName) => CodecName; | ||
| /** | ||
| * Collection of codec types with loose input types | ||
| * | ||
| * Loose codecs are codecs with different typeIn & typeOut, | ||
| * E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32` | ||
| * | ||
| * This registry keep track the list of codecs which follow this convention | ||
| */ | ||
| export declare const looseTypeCodecs: Record<string, AnyShape>; | ||
| export declare function findKnownCodecType(name: string): CodecType; | ||
| export declare function findKnownCodec<I = unknown, O = I>(typeName: string): $.Shape<I, O>; | ||
| export declare function findKnownWrapperCodec(typeName: string): $.AnyShape | undefined; | ||
| export declare function isKnownCodecType(path: string | string[]): boolean; |
| import * as $ from '@dedot/shape'; | ||
| import * as Codecs from '@dedot/codecs'; | ||
| import { $AccountId20, $AccountId32, $Bytes, $ConsensusEngineId, $Era, $EthereumAddress, $MultiAddress, $OpaqueExtrinsic, $PrefixedStorageKey, $RawBytes, $StorageData, $StorageKey, $UncheckedExtrinsic, } from '@dedot/codecs'; | ||
| import { assert } from '@dedot/utils'; | ||
| export const normalizeCodecName = (name) => { | ||
| return name.startsWith('$') ? name : `$${name}`; | ||
| }; | ||
| // Known paths for codecs (primitives) that are shared between | ||
| // different substrate-based blockchains | ||
| const KNOWN_PATHS = [ | ||
| 'sp_core::crypto::AccountId32', | ||
| 'sp_runtime::generic::era::Era', | ||
| 'sp_runtime::multiaddress::MultiAddress', | ||
| /^sp_runtime::DispatchError$/, | ||
| 'sp_runtime::ModuleError', | ||
| 'sp_runtime::TokenError', | ||
| 'sp_arithmetic::ArithmeticError', | ||
| 'sp_runtime::TransactionalError', | ||
| 'frame_support::dispatch::DispatchInfo', | ||
| 'frame_system::Phase', | ||
| 'sp_version::RuntimeVersion', | ||
| 'fp_account::AccountId20', | ||
| 'account::AccountId20', | ||
| 'polkadot_runtime_common::claims::EthereumAddress', | ||
| 'pallet_identity::types::Data', | ||
| 'sp_runtime::generic::digest::Digest', | ||
| 'sp_runtime::generic::digest::DigestItem', | ||
| 'sp_runtime::generic::header::Header', | ||
| 'sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic', | ||
| /^primitive_types::\w+$/, | ||
| /^sp_arithmetic::per_things::\w+$/, | ||
| /^sp_arithmetic::fixed_point::\w+$/, | ||
| ]; | ||
| const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/; | ||
| const TUPLE_TYPE_REGEX = /^\[(.*)]$/; | ||
| const KNOWN_WRAPPER_TYPES = ['Option', 'Vec', 'Result', 'Array']; | ||
| /** | ||
| * Collection of codec types with loose input types | ||
| * | ||
| * Loose codecs are codecs with different typeIn & typeOut, | ||
| * E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32` | ||
| * | ||
| * This registry keep track the list of codecs which follow this convention | ||
| */ | ||
| export const looseTypeCodecs = { | ||
| $AccountId20, | ||
| $EthereumAddress, | ||
| $AccountId32, | ||
| $ConsensusEngineId, | ||
| $StorageKey, | ||
| $StorageData, | ||
| $PrefixedStorageKey, | ||
| $Bytes, | ||
| $RawBytes, | ||
| $MultiAddress, | ||
| $OpaqueExtrinsic, | ||
| $UncheckedExtrinsic, | ||
| $Era, | ||
| }; | ||
| export function findKnownCodecType(name) { | ||
| const normalizedName = normalizeCodecName(name); | ||
| const $knownCodec = looseTypeCodecs[normalizedName]; | ||
| if ($knownCodec) { | ||
| return { | ||
| name: normalizedName, | ||
| $codec: $knownCodec, | ||
| typeIn: `${name}Like`, | ||
| typeOut: name, | ||
| }; | ||
| } | ||
| const $codec = findKnownCodec(name); | ||
| if ($codec.nativeType && $[name]) { | ||
| return { | ||
| name: normalizedName, | ||
| $codec, | ||
| typeIn: $codec.nativeType, | ||
| typeOut: $codec.nativeType, | ||
| }; | ||
| } | ||
| return { | ||
| name: normalizedName, | ||
| $codec, | ||
| typeIn: name, | ||
| typeOut: name, | ||
| }; | ||
| } | ||
| export function findKnownCodec(typeName) { | ||
| // @ts-ignore | ||
| const $codec = findKnownWrapperCodec(typeName) || Codecs[normalizeCodecName(typeName)] || $[typeName]; | ||
| assert($codec, `Known codec not found - ${typeName}`); | ||
| return $codec; | ||
| } | ||
| export function findKnownWrapperCodec(typeName) { | ||
| const matchNames = typeName.match(WRAPPER_TYPE_REGEX); | ||
| if (matchNames) { | ||
| const [_, wrapper, inner] = matchNames; | ||
| if (KNOWN_WRAPPER_TYPES.includes(wrapper)) { | ||
| // @ts-ignore | ||
| const $Wrapper = $[wrapper]; | ||
| if (inner.match(TUPLE_TYPE_REGEX) || inner.match(WRAPPER_TYPE_REGEX)) { | ||
| return $Wrapper(findKnownWrapperCodec(inner)); | ||
| } | ||
| const $inners = inner.split(',').map((one) => findKnownCodec(one.trim())); | ||
| return $Wrapper(...$inners); | ||
| } | ||
| throw new Error(`Unknown wrapper type ${wrapper} from ${typeName}`); | ||
| } | ||
| else if (typeName.match(TUPLE_TYPE_REGEX)) { | ||
| const $inner = typeName | ||
| .slice(1, -1) | ||
| .split(',') | ||
| .filter((x) => x) | ||
| .map((one) => findKnownCodec(one.trim())); | ||
| return $.Tuple(...$inner); | ||
| } | ||
| } | ||
| export function isKnownCodecType(path) { | ||
| const joinedPath = Array.isArray(path) ? path.join('::') : path; | ||
| return KNOWN_PATHS.some((one) => joinedPath.match(one)); | ||
| } |
| /** | ||
| * Known type names registered in @dedot/types | ||
| * Since TS interfaces are trim-off when compiling, | ||
| * So we need to register them explicitly here for RPC codegen process | ||
| */ | ||
| export declare const knownTypes: string[]; |
| /** | ||
| * Known type names registered in @dedot/types | ||
| * Since TS interfaces are trim-off when compiling, | ||
| * So we need to register them explicitly here for RPC codegen process | ||
| */ | ||
| export const knownTypes = [ | ||
| 'ExtrinsicOrHash', | ||
| 'EpochAuthorship', | ||
| 'BlockStats', | ||
| 'Prevotes', | ||
| 'Precommits', | ||
| 'RoundState', | ||
| 'ReportedRoundStates', | ||
| 'JustificationNotification', | ||
| 'EncodedFinalityProofs', | ||
| 'LeavesProof', | ||
| 'StorageKind', | ||
| 'RpcMethods', | ||
| 'ReadProof', | ||
| 'StorageChangeSet', | ||
| 'TraceBlockResponse', | ||
| 'MigrationStatusResult', | ||
| 'ChainType', | ||
| 'ChainProperties', | ||
| 'Health', | ||
| 'SyncState', | ||
| 'PeerInfo', | ||
| 'NodeRole', | ||
| 'NetworkState', | ||
| ]; |
@@ -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 @@ } |
+10
-10
@@ -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) { |
+16
-15
@@ -6,4 +6,5 @@ "use strict"; | ||
| const utils_1 = require("@dedot/utils"); | ||
| const generator_1 = require("../generator"); | ||
| const utils_2 = require("./utils"); | ||
| 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 = [ | ||
@@ -13,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; | ||
@@ -67,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 })); | ||
| } | ||
@@ -79,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`; | ||
| } | ||
@@ -98,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}>>`; | ||
| } | ||
@@ -116,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); | ||
@@ -130,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); | ||
@@ -151,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)}>`; | ||
@@ -165,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 | ||
@@ -180,3 +181,3 @@ .slice(1, -1) | ||
| #getCodecType(type, toTypeIn = true) { | ||
| const { typeIn, typeOut } = this.registry.findCodecType(type); | ||
| const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type); | ||
| return toTypeIn ? typeIn : typeOut; | ||
@@ -183,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,7 +102,7 @@ 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}>>`; | ||
| } | ||
| #targetRuntimeApiSpecs() { | ||
| const specs = this.runtimeApis.map(([runtimeApiHash, version]) => { | ||
| const runtimeApiSpec = (0, specs_1.findRuntimeApiSpec)(runtimeApiHash, version); | ||
| const runtimeApiSpec = this.#findRuntimeApiSpec(runtimeApiHash, version); | ||
| if (!runtimeApiSpec) | ||
@@ -122,3 +122,7 @@ return; | ||
| } | ||
| #findRuntimeApiSpec = (runtimeApiHash, version) => { | ||
| 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); | ||
| }; | ||
| } | ||
| exports.RuntimeApisGen = RuntimeApisGen; |
| "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,5 +7,6 @@ "use strict"; | ||
| const utils_1 = require("@dedot/utils"); | ||
| const utils_2 = require("./utils"); | ||
| const types_1 = require("@dedot/types"); | ||
| const TypeImports_1 = require("./TypeImports"); | ||
| 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 | ||
@@ -44,5 +45,5 @@ // as we do have native types for them | ||
| this.metadata = metadata; | ||
| this.registry = new codecs_1.CodecRegistry(this.metadata); | ||
| this.registry = new codecs_1.PortableRegistry(this.metadata); | ||
| this.includedTypes = this.#includedTypes(); | ||
| this.typeImports = new TypeImports_1.TypeImports(); | ||
| this.typeImports = new TypeImports_js_1.TypeImports(); | ||
| } | ||
@@ -55,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)) { | ||
@@ -62,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 })); | ||
| } | ||
@@ -109,3 +110,3 @@ typeCache = {}; | ||
| case 'Primitive': | ||
| const $codec = this.registry.findCodec(value.kind); | ||
| const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind); | ||
| if ($codec.nativeType) { | ||
@@ -158,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(' | '); | ||
| } | ||
@@ -172,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(', ')}]`; | ||
@@ -181,3 +182,3 @@ membersType.push([keyName, valueType, docs]); | ||
| } | ||
| const { tagKey, valueKey } = this.registry.portableRegistry.getEnumOptions(typeId); | ||
| const { tagKey, valueKey } = this.registry.getEnumOptions(typeId); | ||
| return membersType | ||
@@ -189,3 +190,3 @@ .map(([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 +238,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 +280,4 @@ } | ||
| let name, nameOut; | ||
| if (this.registry.isKnownType(joinedPath)) { | ||
| const codecType = this.registry.findCodecType(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; | ||
@@ -334,3 +335,3 @@ nameOut = codecType.typeOut; | ||
| const { callTypeId } = this.metadata.extrinsic; | ||
| const palletCallTypeIds = this.registry.portableRegistry.getPalletCallTypeIds(); | ||
| const palletCallTypeIds = this.registry.getPalletCallTypeIds(); | ||
| return callTypeId === id || palletCallTypeIds.includes(id); | ||
@@ -440,3 +441,3 @@ } | ||
| } | ||
| if (types_1.registry.has(typeName)) { | ||
| if (known_types_js_1.knownTypes.includes(typeName)) { | ||
| this.typeImports.addKnownType(typeName); | ||
@@ -443,0 +444,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"); | ||
@@ -43,2 +43,6 @@ const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex")); | ||
| { | ||
| chain: 'rococo', | ||
| endpoint: 'wss://rococo-rpc.polkadot.io/', | ||
| }, | ||
| { | ||
| chain: 'rococoAssetHub', | ||
@@ -62,3 +66,3 @@ endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/', | ||
| 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); | ||
| } | ||
@@ -69,3 +73,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); | ||
| } | ||
@@ -76,3 +80,3 @@ } | ||
| const getRuntimeVersion = (metadata) => { | ||
| const registry = new codecs_1.CodecRegistry(metadata.latest); | ||
| const registry = new codecs_1.PortableRegistry(metadata.latest); | ||
| const executor = new dedot_1.ConstantExecutor({ | ||
@@ -79,0 +83,0 @@ registry, |
+10
-10
@@ -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.26' }; | ||
| 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 { | ||
@@ -47,3 +47,3 @@ readonly typesGen: TypesGen; | ||
| value: { | ||
| kind: "bool" | "char" | "str" | "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256"; | ||
| kind: "bool" | "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "u256" | "i256" | "str" | "char"; | ||
| }; | ||
@@ -138,3 +138,3 @@ } | { | ||
| }; | ||
| get registry(): import("@dedot/codecs").CodecRegistry; | ||
| get registry(): import("@dedot/codecs").PortableRegistry; | ||
| } |
@@ -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'; |
+10
-10
@@ -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'; |
+10
-10
@@ -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 { 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 = [ | ||
@@ -168,5 +169,5 @@ // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158 | ||
| #getCodecType(type, toTypeIn = true) { | ||
| const { typeIn, typeOut } = this.registry.findCodecType(type); | ||
| const { typeIn, typeOut } = findKnownCodecType(type); | ||
| return toTypeIn ? typeIn : typeOut; | ||
| } | ||
| } |
@@ -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; |
@@ -1,5 +0,5 @@ | ||
| import { findRuntimeApiSpec } from '@dedot/specs'; | ||
| import { beautifySourceCode, commentBlock, compileTemplate } from './utils'; | ||
| import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs'; | ||
| 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'; | ||
@@ -96,3 +96,3 @@ export class RuntimeApisGen extends RpcGen { | ||
| const specs = this.runtimeApis.map(([runtimeApiHash, version]) => { | ||
| const runtimeApiSpec = findRuntimeApiSpec(runtimeApiHash, version); | ||
| const runtimeApiSpec = this.#findRuntimeApiSpec(runtimeApiHash, version); | ||
| if (!runtimeApiSpec) | ||
@@ -112,2 +112,6 @@ return; | ||
| } | ||
| #findRuntimeApiSpec = (runtimeApiHash, version) => { | ||
| const runtimeApiName = getRuntimeApiNames().find((one) => calculateRuntimeApiHash(one) === runtimeApiHash); | ||
| return getRuntimeApiSpecs().find((one) => one.runtimeApiName === runtimeApiName && one.version === version); | ||
| }; | ||
| } |
@@ -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() { |
@@ -1,3 +0,3 @@ | ||
| import { CodecRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs'; | ||
| import { TypeImports } from './TypeImports'; | ||
| import { PortableRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs'; | ||
| import { TypeImports } from './TypeImports.js'; | ||
| interface NamedType extends PortableType { | ||
@@ -18,3 +18,3 @@ name: string; | ||
| includedTypes: Record<TypeId, NamedType>; | ||
| registry: CodecRegistry; | ||
| registry: PortableRegistry; | ||
| typeImports: TypeImports; | ||
@@ -21,0 +21,0 @@ constructor(metadata: MetadataLatest); |
+12
-11
| import { stringPascalCase } from '@polkadot/util'; | ||
| import { CodecRegistry } from '@dedot/codecs'; | ||
| import { PortableRegistry } from '@dedot/codecs'; | ||
| import { isNativeType, normalizeName } from '@dedot/utils'; | ||
| import { beautifySourceCode, commentBlock, compileTemplate } from './utils'; | ||
| import { registry } from '@dedot/types'; | ||
| import { TypeImports } from './TypeImports'; | ||
| 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 | ||
@@ -40,3 +41,3 @@ // as we do have native types for them | ||
| this.metadata = metadata; | ||
| this.registry = new CodecRegistry(this.metadata); | ||
| this.registry = new PortableRegistry(this.metadata); | ||
| this.includedTypes = this.#includedTypes(); | ||
@@ -103,3 +104,3 @@ this.typeImports = new TypeImports(); | ||
| case 'Primitive': | ||
| const $codec = this.registry.findCodec(value.kind); | ||
| const $codec = findKnownCodec(value.kind); | ||
| if ($codec.nativeType) { | ||
@@ -173,3 +174,3 @@ return $codec.nativeType; | ||
| } | ||
| const { tagKey, valueKey } = this.registry.portableRegistry.getEnumOptions(typeId); | ||
| const { tagKey, valueKey } = this.registry.getEnumOptions(typeId); | ||
| return membersType | ||
@@ -269,4 +270,4 @@ .map(([keyName, valueType, docs]) => ({ | ||
| let name, nameOut; | ||
| if (this.registry.isKnownType(joinedPath)) { | ||
| const codecType = this.registry.findCodecType(path.at(-1)); | ||
| if (isKnownCodecType(joinedPath)) { | ||
| const codecType = findKnownCodecType(path.at(-1)); | ||
| name = codecType.typeIn; | ||
@@ -324,3 +325,3 @@ nameOut = codecType.typeOut; | ||
| const { callTypeId } = this.metadata.extrinsic; | ||
| const palletCallTypeIds = this.registry.portableRegistry.getPalletCallTypeIds(); | ||
| const palletCallTypeIds = this.registry.getPalletCallTypeIds(); | ||
| return callTypeId === id || palletCallTypeIds.includes(id); | ||
@@ -430,3 +431,3 @@ } | ||
| } | ||
| if (registry.has(typeName)) { | ||
| if (knownTypes.includes(typeName)) { | ||
| this.typeImports.addKnownType(typeName); | ||
@@ -433,0 +434,0 @@ } |
@@ -1,5 +0,5 @@ | ||
| import { generateTypes, generateTypesFromChain } from './index'; | ||
| import { generateTypes, generateTypesFromChain } from './index.js'; | ||
| import { rpc } from '@polkadot/types-support/metadata/static-substrate'; | ||
| import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex'; | ||
| import { $Metadata, CodecRegistry } from '@dedot/codecs'; | ||
| import { $Metadata, PortableRegistry } from '@dedot/codecs'; | ||
| import { ConstantExecutor } from 'dedot'; | ||
@@ -37,2 +37,6 @@ const NETWORKS = [ | ||
| { | ||
| chain: 'rococo', | ||
| endpoint: 'wss://rococo-rpc.polkadot.io/', | ||
| }, | ||
| { | ||
| chain: 'rococoAssetHub', | ||
@@ -68,3 +72,3 @@ endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/', | ||
| const getRuntimeVersion = (metadata) => { | ||
| const registry = new CodecRegistry(metadata.latest); | ||
| const registry = new PortableRegistry(metadata.latest); | ||
| const executor = new ConstantExecutor({ | ||
@@ -71,0 +75,0 @@ registry, |
+1
-1
| 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>; |
+1
-1
| 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) { |
+7
-7
| { | ||
| "name": "@dedot/codegen", | ||
| "version": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "version": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "description": "Generate types", | ||
@@ -21,8 +21,8 @@ "author": "Thang X. Vu <thang@coongcrafts.io>", | ||
| "dependencies": { | ||
| "@dedot/codecs": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "@dedot/shape": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "@dedot/specs": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "@dedot/utils": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "@dedot/codecs": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "@dedot/shape": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "@dedot/specs": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "@dedot/utils": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "@polkadot/util": "^12.6.2", | ||
| "dedot": "0.0.1-next.ebf1326c.6+ebf1326", | ||
| "dedot": "0.0.1-next.f1aed4d8.4+f1aed4d", | ||
| "handlebars": "^4.7.8", | ||
@@ -36,3 +36,3 @@ "prettier": "^3.0.3" | ||
| "license": "Apache-2.0", | ||
| "gitHead": "ebf1326cd643a47da630f942b5d6cb67e3a8bc82", | ||
| "gitHead": "f1aed4d898adac80ec66097c705a193a9b22d855", | ||
| "module": "./index.js", | ||
@@ -39,0 +39,0 @@ "types": "./index.d.ts", |
+1
-1
| // THIS FILE IS AUTO-GENERATED, DO NOT EDIT! | ||
| export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.26' }; | ||
| export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' }; |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
149590
10.72%82
7.89%3239
13.41%