diff --git a/CHANGELOG.md b/CHANGELOG.md index a509461d07..001ad527dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - (internal) Remove [11 Jan 2019](https://github.com/polkadot-js/api/issues/574) extrinsic length hack - (internal) Use ES `#` on private class members as applicable - (internal) Move `types/primitive/{extrinsics, generic}` to `types/{extrinsics, generic}` +- (internal) Cleanup augmentation and generation scripts of `interfaceRegistry` in types, aligning with api # 1.3.1 Feb 18, 2020 diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index e37452eb96..e7145ba4d6 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -4,7 +4,6 @@ import { Constants, Storage } from '@polkadot/metadata/Decorated/types'; import { RpcInterface } from '@polkadot/rpc-core/types'; -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces'; import { AnyFunction, CallFunction, Codec, CodecArg as Arg, ITuple, InterfaceTypes, ModulesWithCalls, Registry, RegistryTypes } from '@polkadot/types/types'; import { SubmittableExtrinsic } from '../submittable/types'; @@ -137,7 +136,7 @@ export default abstract class Decorate extends Events this._rx.registry = this.registry; } - public abstract createType (type: K, ...params: any[]): InterfaceRegistry[K]; + public abstract createType (type: K, ...params: any[]): InterfaceTypes[K]; public abstract registerTypes (types?: RegistryTypes): void; diff --git a/packages/api/src/base/index.ts b/packages/api/src/base/index.ts index faf28fefca..0124480664 100644 --- a/packages/api/src/base/index.ts +++ b/packages/api/src/base/index.ts @@ -5,7 +5,6 @@ import { Constants } from '@polkadot/metadata/Decorated/types'; import { RpcInterface } from '@polkadot/rpc-core/types'; import { Hash, RuntimeVersion } from '@polkadot/types/interfaces'; -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { CallFunction, InterfaceTypes, RegistryError, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types'; import { ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedRpc, DecorateMethod, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics, Signer } from '../types'; @@ -237,7 +236,7 @@ export default abstract class ApiBase extends Init (type: K, ...params: any[]): InterfaceRegistry[K] => { + public createType = (type: K, ...params: any[]): InterfaceTypes[K] => { return createType(this.registry, type, ...params); } diff --git a/packages/jsonrpc/src/create/param.ts b/packages/jsonrpc/src/create/param.ts index f1b5c24817..ec3645c8ea 100644 --- a/packages/jsonrpc/src/create/param.ts +++ b/packages/jsonrpc/src/create/param.ts @@ -10,7 +10,7 @@ interface RpcParamOptions { } /** @internal */ -export default function createParam (name: string, type: InterfaceTypes, { isOptional = false }: RpcParamOptions = { isOptional: false }): RpcParam { +export default function createParam (name: string, type: keyof InterfaceTypes, { isOptional = false }: RpcParamOptions = { isOptional: false }): RpcParam { return { isOptional, name, diff --git a/packages/jsonrpc/src/state.ts b/packages/jsonrpc/src/state.ts index 4577f351c2..98dc6d95a0 100644 --- a/packages/jsonrpc/src/state.ts +++ b/packages/jsonrpc/src/state.ts @@ -85,7 +85,7 @@ const getMetadata: RpcMethodOpt = { params: [ createParam('at', 'BlockHash', { isOptional: true }) ], - // This is not part of InterfaceTypes + // This is not part of keyof InterfaceTypes type: 'Metadata' as any }; diff --git a/packages/jsonrpc/src/types.ts b/packages/jsonrpc/src/types.ts index da87c5c3e4..f66d06c3e3 100644 --- a/packages/jsonrpc/src/types.ts +++ b/packages/jsonrpc/src/types.ts @@ -9,7 +9,7 @@ type PubSub = [string, string, string]; export interface RpcParam { isOptional: boolean; name: string; - type: InterfaceTypes; + type: keyof InterfaceTypes; } export interface RpcMethodOpt { @@ -21,7 +21,7 @@ export interface RpcMethodOpt { isSubscription?: boolean; params: RpcParam[]; pubsub?: PubSub; - type: InterfaceTypes; + type: keyof InterfaceTypes; } export interface RpcMethod { @@ -36,7 +36,7 @@ export interface RpcMethod { params: RpcParam[]; pubsub: PubSub; section: string; - type: InterfaceTypes; + type: keyof InterfaceTypes; } export interface RpcSection { diff --git a/packages/typegen/src/fromDefs.ts b/packages/typegen/src/fromDefs.ts index 83fc6049be..cd1543dcb3 100644 --- a/packages/typegen/src/fromDefs.ts +++ b/packages/typegen/src/fromDefs.ts @@ -6,7 +6,7 @@ import path from 'path'; import yargs from 'yargs'; import * as substrateDefs from '@polkadot/types/interfaces/definitions'; -import { generateInterfaceRegistry } from './generate/interfaceRegistry'; +import { generateInterfaceTypes } from './generate/interfaceRegistry'; import { generateTsDef } from './generate/tsDef'; export default function main (): void { @@ -49,5 +49,5 @@ export default function main (): void { }; generateTsDef(allDefs, path.join(process.cwd(), input), pkg); - generateInterfaceRegistry(allDefs, path.join(process.cwd(), input, 'augment-types.ts')); + generateInterfaceTypes(allDefs, path.join(process.cwd(), input, 'augment-types.ts')); } diff --git a/packages/typegen/src/generate/interfaceRegistry.ts b/packages/typegen/src/generate/interfaceRegistry.ts index e28ea6be3d..3772a83a8d 100644 --- a/packages/typegen/src/generate/interfaceRegistry.ts +++ b/packages/typegen/src/generate/interfaceRegistry.ts @@ -14,7 +14,7 @@ const primitiveClasses = { }; /** @internal */ -export function generateInterfaceRegistry (importDefinitions: { [importPath: string]: object }, dest: string): void { +export function generateInterfaceTypes (importDefinitions: { [importPath: string]: object }, dest: string): void { writeFile(dest, (): string => { Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {} as object); @@ -51,7 +51,7 @@ export function generateInterfaceRegistry (importDefinitions: { [importPath: str })) ]); - const interfaceStart = "declare module '@polkadot/types/interfaceRegistry' {\n export interface InterfaceRegistry {"; + const interfaceStart = "declare module '@polkadot/types/types/registry' {\n export interface InterfaceTypes {"; const interfaceEnd = '\n }\n}'; return header @@ -64,9 +64,9 @@ export function generateInterfaceRegistry (importDefinitions: { [importPath: str } // Generate `packages/types/src/interfaceRegistry.ts`, the registry of all interfaces -export default function generateDefaultInterfaceRegistry (): void { - generateInterfaceRegistry( +export default function generateDefaultInterfaceTypes (): void { + generateInterfaceTypes( { '@polkadot/types/interfaces': defaultDefinitions }, - 'packages/types/src/augment/interfaceRegistry.ts' + 'packages/types/src/augment/registry.ts' ); } diff --git a/packages/typegen/src/interfacesTs.ts b/packages/typegen/src/interfacesTs.ts index 00dda8292e..e685a92042 100644 --- a/packages/typegen/src/interfacesTs.ts +++ b/packages/typegen/src/interfacesTs.ts @@ -3,14 +3,14 @@ // of the Apache-2.0 license. See the LICENSE file for details. import generateConstsTypes from './generate/consts'; -import generateInterfaceRegistry from './generate/interfaceRegistry'; +import generateInterfaceTypes from './generate/interfaceRegistry'; import generateQueryTypes from './generate/query'; import generateRpcTypes from './generate/rpc'; import generateTsDef from './generate/tsDef'; import generateTxTypes from './generate/tx'; export default function main (): void { - generateInterfaceRegistry(); + generateInterfaceTypes(); generateConstsTypes(); generateQueryTypes(); diff --git a/packages/types/src/augment/index.ts b/packages/types/src/augment/index.ts index f0a491a96f..2e165cdb2f 100644 --- a/packages/types/src/augment/index.ts +++ b/packages/types/src/augment/index.ts @@ -2,4 +2,4 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import './interfaceRegistry'; +import './registry'; diff --git a/packages/types/src/augment/interfaceRegistry.ts b/packages/types/src/augment/registry.ts similarity index 99% rename from packages/types/src/augment/interfaceRegistry.ts rename to packages/types/src/augment/registry.ts index 696560c5cc..b990c5f2cb 100644 --- a/packages/types/src/augment/interfaceRegistry.ts +++ b/packages/types/src/augment/registry.ts @@ -37,8 +37,8 @@ import { Multiplier } from '@polkadot/types/interfaces/txpayment'; import { Multisig, Timepoint } from '@polkadot/types/interfaces/utility'; import { VestingInfo } from '@polkadot/types/interfaces/vesting'; -declare module '@polkadot/types/interfaceRegistry' { - export interface InterfaceRegistry { +declare module '@polkadot/types/types/registry' { + export interface InterfaceTypes { BitVec: BitVec; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/codec/BTreeMap.ts b/packages/types/src/codec/BTreeMap.ts index 56d47f720c..5995451cf1 100644 --- a/packages/types/src/codec/BTreeMap.ts +++ b/packages/types/src/codec/BTreeMap.ts @@ -19,7 +19,7 @@ export default class BTreeMap private readonly _ValClass: Constructor; - constructor (registry: Registry, keyType: Constructor | InterfaceTypes, valType: Constructor | InterfaceTypes, rawValue: any) { + constructor (registry: Registry, keyType: Constructor | keyof InterfaceTypes, valType: Constructor | keyof InterfaceTypes, rawValue: any) { const KeyClass = typeToConstructor(registry, keyType); const ValClass = typeToConstructor(registry, valType); @@ -98,7 +98,7 @@ export default class BTreeMap return output; } - public static with (keyType: Constructor | InterfaceTypes, valType: Constructor | InterfaceTypes): Constructor> { + public static with (keyType: Constructor | keyof InterfaceTypes, valType: Constructor | keyof InterfaceTypes): Constructor> { return class extends BTreeMap { constructor (registry: Registry, value?: any) { super(registry, keyType, valType, value); diff --git a/packages/types/src/codec/BTreeSet.ts b/packages/types/src/codec/BTreeSet.ts index f43f6b5c27..5ea24d277d 100644 --- a/packages/types/src/codec/BTreeSet.ts +++ b/packages/types/src/codec/BTreeSet.ts @@ -17,7 +17,7 @@ export default class BTreeSet extends Set implements private readonly _ValClass: Constructor; - constructor (registry: Registry, valType: Constructor | InterfaceTypes, rawValue: any) { + constructor (registry: Registry, valType: Constructor | keyof InterfaceTypes, rawValue: any) { const ValClass = typeToConstructor(registry, valType); super(BTreeSet.decodeBTreeSet(registry, ValClass, rawValue)); @@ -92,7 +92,7 @@ export default class BTreeSet extends Set implements return output; } - public static with (valType: Constructor | InterfaceTypes): Constructor> { + public static with (valType: Constructor | keyof InterfaceTypes): Constructor> { return class extends BTreeSet { constructor (registry: Registry, value?: any) { super(registry, valType, value); diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index e573bc4553..bbf208c877 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -27,11 +27,11 @@ export interface CompactEncodable extends Codec { * a number and making the compact representation thereof */ export default class Compact extends Base implements ICompact { - constructor (registry: Registry, Type: Constructor | InterfaceTypes, value: Compact | AnyNumber = 0) { + constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value: Compact | AnyNumber = 0) { super(registry, Compact.decodeCompact(registry, typeToConstructor(registry, Type), value)); } - public static with (Type: Constructor | InterfaceTypes): Constructor> { + public static with (Type: Constructor | keyof InterfaceTypes): Constructor> { return class extends Compact { constructor (registry: Registry, value?: any) { super(registry, Type, value); diff --git a/packages/types/src/codec/Enum.ts b/packages/types/src/codec/Enum.ts index 1090125fa7..2b3196a509 100644 --- a/packages/types/src/codec/Enum.ts +++ b/packages/types/src/codec/Enum.ts @@ -23,7 +23,7 @@ interface Decoded { value: Codec; } -function extractDef (registry: Registry, _def: Record | string[]): { def: TypesDef; isBasic: boolean } { +function extractDef (registry: Registry, _def: Record | string[]): { def: TypesDef; isBasic: boolean } { if (!Array.isArray(_def)) { const def = mapToTypeMap(registry, _def); const isBasic = !Object.values(def).some((type): boolean => type !== Null); @@ -123,7 +123,7 @@ export default class Enum extends Base { private _isBasic: boolean; - constructor (registry: Registry, def: Record | string[], value?: any, index?: number) { + constructor (registry: Registry, def: Record | string[], value?: any, index?: number) { const defInfo = extractDef(registry, def); const decoded = decodeEnum(registry, defInfo.def, value, index); @@ -135,7 +135,7 @@ export default class Enum extends Base { this._index = this._indexes.indexOf(decoded.index) || 0; } - public static with (Types: Record | string[]): EnumConstructor { + public static with (Types: Record | string[]): EnumConstructor { return class extends Enum { constructor (registry: Registry, value?: any, index?: number) { super(registry, Types, value, index); diff --git a/packages/types/src/codec/Linkage.ts b/packages/types/src/codec/Linkage.ts index 82c8be5bd1..2f184b898a 100644 --- a/packages/types/src/codec/Linkage.ts +++ b/packages/types/src/codec/Linkage.ts @@ -18,14 +18,14 @@ const EMPTY = new Uint8Array(); * @description The wrapper for the result from a LinkedMap */ export default class Linkage extends Struct { - constructor (registry: Registry, Type: Constructor | InterfaceTypes, value?: any) { + constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value?: any) { super(registry, { previous: Option.with(Type), next: Option.with(Type) }, value); } - public static withKey (Type: Constructor | InterfaceTypes): Constructor> { + public static withKey (Type: Constructor | keyof InterfaceTypes): Constructor> { return class extends Linkage { constructor (registry: Registry, value?: any) { super(registry, Type, value); diff --git a/packages/types/src/codec/Option.ts b/packages/types/src/codec/Option.ts index d7944f6bd2..3104a02f0d 100644 --- a/packages/types/src/codec/Option.ts +++ b/packages/types/src/codec/Option.ts @@ -21,7 +21,7 @@ import Base from './Base'; export default class Option extends Base { private _Type: Constructor; - constructor (registry: Registry, Type: Constructor | InterfaceTypes, value?: any) { + constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value?: any) { const Clazz = typeToConstructor(registry, Type); super(registry, Option.decodeOption(registry, Clazz, value)); @@ -54,7 +54,7 @@ export default class Option extends Base { : new Type(registry, value.subarray(1)); } - public static with (Type: Constructor | InterfaceTypes): Constructor> { + public static with (Type: Constructor | keyof InterfaceTypes): Constructor> { return class extends Option { constructor (registry: Registry, value?: any) { super(registry, Type, value); diff --git a/packages/types/src/codec/Result.ts b/packages/types/src/codec/Result.ts index 212dee1831..3f1fd6d5b7 100644 --- a/packages/types/src/codec/Result.ts +++ b/packages/types/src/codec/Result.ts @@ -14,12 +14,12 @@ import Enum from './Enum'; * A Result maps to the Rust Result type, that can either wrap a success or error value */ export default class Result extends Enum { - constructor (registry: Registry, Ok: Constructor | InterfaceTypes, Error: Constructor | InterfaceTypes, value?: any) { + constructor (registry: Registry, Ok: Constructor | keyof InterfaceTypes, Error: Constructor | keyof InterfaceTypes, value?: any) { // NOTE This is order-dependent, Ok (with index 0) needs to be first super(registry, { Ok, Error }, value); } - public static with (Types: { Ok: Constructor | InterfaceTypes; Error: Constructor | InterfaceTypes }): Constructor> { + public static with (Types: { Ok: Constructor | keyof InterfaceTypes; Error: Constructor | keyof InterfaceTypes }): Constructor> { return class extends Result { constructor (registry: Registry, value?: any) { super(registry, Types.Ok, Types.Error, value); diff --git a/packages/types/src/codec/Struct.ts b/packages/types/src/codec/Struct.ts index cba54aeee9..6ba605d59f 100644 --- a/packages/types/src/codec/Struct.ts +++ b/packages/types/src/codec/Struct.ts @@ -11,7 +11,7 @@ import { blake2AsU8a } from '@polkadot/util-crypto'; import Raw from './Raw'; import { compareMap, decodeU8a, mapToTypeMap } from './utils'; -type TypesDef = Record>; +type TypesDef = Record>; /** @internal */ function decodeStructFromObject (registry: Registry, Types: ConstructorDef, value: any, jsonMap: Map): T { diff --git a/packages/types/src/codec/Tuple.ts b/packages/types/src/codec/Tuple.ts index 5f5018a5b1..9525d91f6d 100644 --- a/packages/types/src/codec/Tuple.ts +++ b/packages/types/src/codec/Tuple.ts @@ -13,8 +13,8 @@ type TupleConstructors = Constructor[] | { [index: string]: Constructor; }; -type TupleTypes = (Constructor | InterfaceTypes)[] | { - [index: string]: Constructor | InterfaceTypes; +type TupleTypes = (Constructor | keyof InterfaceTypes)[] | { + [index: string]: Constructor | keyof InterfaceTypes; }; /** diff --git a/packages/types/src/codec/Vec.ts b/packages/types/src/codec/Vec.ts index 321e8e0b43..312be5f347 100644 --- a/packages/types/src/codec/Vec.ts +++ b/packages/types/src/codec/Vec.ts @@ -22,7 +22,7 @@ const MAX_LENGTH = 32768; export default class Vec extends AbstractArray { private _Type: Constructor; - constructor (registry: Registry, Type: Constructor | InterfaceTypes, value: Vec | Uint8Array | string | any[] = [] as any[]) { + constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value: Vec | Uint8Array | string | any[] = [] as any[]) { const Clazz = typeToConstructor(registry, Type); super(registry, ...Vec.decodeVec(registry, Clazz, value)); @@ -54,7 +54,7 @@ export default class Vec extends AbstractArray { return decodeU8a(registry, u8a.subarray(offset), new Array(length.toNumber()).fill(Type)) as T[]; } - public static with (Type: Constructor | InterfaceTypes): Constructor> { + public static with (Type: Constructor | keyof InterfaceTypes): Constructor> { return class extends Vec { constructor (registry: Registry, value?: any[]) { super(registry, Type, value); diff --git a/packages/types/src/codec/VecFixed.ts b/packages/types/src/codec/VecFixed.ts index 3d7460b5c0..9336aa13a1 100644 --- a/packages/types/src/codec/VecFixed.ts +++ b/packages/types/src/codec/VecFixed.ts @@ -17,7 +17,7 @@ import Vec from './Vec'; export default class VecFixed extends AbstractArray { private _Type: Constructor; - constructor (registry: Registry, Type: Constructor | InterfaceTypes, length: number, value: VecFixed | Uint8Array | string | any[] = [] as any[]) { + constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, length: number, value: VecFixed | Uint8Array | string | any[] = [] as any[]) { const Clazz = typeToConstructor(registry, Type); super(registry, ...VecFixed.decodeVecFixed(registry, Clazz, length, value)); @@ -44,7 +44,7 @@ export default class VecFixed extends AbstractArray { return values; } - public static with (Type: Constructor | InterfaceTypes, length: number): Constructor> { + public static with (Type: Constructor | keyof InterfaceTypes, length: number): Constructor> { return class extends VecFixed { constructor (registry: Registry, value?: any[]) { super(registry, Type, length, value); diff --git a/packages/types/src/codec/utils/mapToTypeMap.ts b/packages/types/src/codec/utils/mapToTypeMap.ts index 4df91de53e..5241ab5d0e 100644 --- a/packages/types/src/codec/utils/mapToTypeMap.ts +++ b/packages/types/src/codec/utils/mapToTypeMap.ts @@ -8,7 +8,7 @@ import { isString } from '@polkadot/util'; import { ClassOf } from '../../create/createClass'; -export function typeToConstructor (registry: Registry, type: InterfaceTypes | Constructor): Constructor { +export function typeToConstructor (registry: Registry, type: keyof InterfaceTypes | Constructor): Constructor { return ( isString(type) ? ClassOf(registry, type) @@ -19,7 +19,7 @@ export function typeToConstructor (registry: Registry, type: Interfa /** * @description takes an input map of the form `{ [string]: string | Constructor }` and returns a map of `{ [string]: Constructor }` */ -export function mapToTypeMap (registry: Registry, input: Record): Record { +export function mapToTypeMap (registry: Registry, input: Record): Record { return Object .entries(input) .reduce((output: Record, [key, type]): Record => { diff --git a/packages/types/src/create/createClass.ts b/packages/types/src/create/createClass.ts index 03924f2e12..4ba6af583d 100644 --- a/packages/types/src/create/createClass.ts +++ b/packages/types/src/create/createClass.ts @@ -2,7 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { Codec, Constructor, InterfaceTypes, Registry } from '../types'; import { FromReg, TypeDef, TypeDefInfo } from './types'; @@ -38,9 +37,9 @@ export function ClassOfUnsafe (registry: Registry, name: K): Constructor { +export function ClassOf (registry: Registry, name: K): Constructor { // TS2589: Type instantiation is excessively deep and possibly infinite. - // The above happens with as Constructor; + // The above happens with as Constructor; return ClassOfUnsafe(registry, name) as any; } @@ -56,15 +55,15 @@ function getSubDef (value: TypeDef): TypeDef { return value.sub; } -function getSubType (value: TypeDef): InterfaceTypes { - return getSubDef(value).type as InterfaceTypes; +function getSubType (value: TypeDef): keyof InterfaceTypes { + return getSubDef(value).type as keyof InterfaceTypes; } // create a maps of type string constructors from the input -function getTypeClassMap (value: TypeDef): Record { - const result: Record = {}; +function getTypeClassMap (value: TypeDef): Record { + const result: Record = {}; - return getSubDefArray(value).reduce((result, sub): Record => { + return getSubDefArray(value).reduce((result, sub): Record => { result[sub.name as string] = sub.type as any; return result; @@ -72,9 +71,9 @@ function getTypeClassMap (value: TypeDef): Record { } // create an array of type string constructors from the input -function getTypeClassArray (value: TypeDef): (InterfaceTypes)[] { - return getSubDefArray(value).map(({ type }): InterfaceTypes => - type as InterfaceTypes +function getTypeClassArray (value: TypeDef): (keyof InterfaceTypes)[] { + return getSubDefArray(value).map(({ type }): keyof InterfaceTypes => + type as keyof InterfaceTypes ); } @@ -162,7 +161,7 @@ const infoMapping: Record C return ( (sub as TypeDef).type === 'u8' ? U8aFixed.with((length * 8) as U8aFixedBitLength, displayName) - : VecFixed.with((sub as TypeDef).type as InterfaceTypes, length) + : VecFixed.with((sub as TypeDef).type as keyof InterfaceTypes, length) ); } }; diff --git a/packages/types/src/create/createType.ts b/packages/types/src/create/createType.ts index 35710a8263..50031c1dec 100644 --- a/packages/types/src/create/createType.ts +++ b/packages/types/src/create/createType.ts @@ -2,7 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { Codec, Constructor, InterfaceTypes, Registry } from '../types'; import { FromReg } from './types'; @@ -74,6 +73,6 @@ export function createTypeUnsafe (registry: Registry, type: K, ...params: any[]): InterfaceRegistry[K] { - return createTypeUnsafe(registry, type, params); +export function createType (registry: Registry, type: K, ...params: any[]): InterfaceTypes[K] { + return createTypeUnsafe(registry, type, params); } diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index afb84755ac..dc93a1fb20 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -213,11 +213,11 @@ export class TypeRegistry implements Registry { return this.get(name, true) as Constructor; } - public getSignedExtensionExtra (): Record { + public getSignedExtensionExtra (): Record { return expandExtensionTypes(this.#metadataExtensions, 'extra'); } - public getSignedExtensionTypes (): Record { + public getSignedExtensionTypes (): Record { return expandExtensionTypes(this.#metadataExtensions, 'types'); } diff --git a/packages/types/src/create/types.ts b/packages/types/src/create/types.ts index 59d19d7de3..021f7d3625 100644 --- a/packages/types/src/create/types.ts +++ b/packages/types/src/create/types.ts @@ -2,12 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; import { Codec, InterfaceTypes } from '../types'; -// Type which says: if `K` is in the InterfaceRegistry, then return InterfaceRegistry[K], else fallback to T -export type FromReg = K extends InterfaceTypes - ? InterfaceRegistry[K] +// Type which says: if `K` is in the InterfaceTypes, then return InterfaceTypes[K], else fallback to T +export type FromReg = K extends keyof InterfaceTypes + ? InterfaceTypes[K] : T; export enum TypeDefInfo { diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index f9ebe004ed..82c4a915fb 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -29,7 +29,7 @@ interface CreateOptions { type ExtrinsicVx = ExtrinsicV1 | ExtrinsicV2 | ExtrinsicV3 | ExtrinsicV4; type ExtrinsicValue = ExtrinsicValueV1 | ExtrinsicValueV2 | ExtrinsicValueV3 | ExtrinsicValueV4; -const VERSIONS: InterfaceTypes[] = [ +const VERSIONS: (keyof InterfaceTypes)[] = [ 'ExtrinsicUnknown', // v0 is unknown 'ExtrinsicV1', 'ExtrinsicV2', diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index 31a420a969..17f1b54982 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -23,7 +23,7 @@ interface ExtrinsicPayloadOptions { // all our known types that can be returned type ExtrinsicPayloadVx = ExtrinsicPayloadV1 | ExtrinsicPayloadV2 | ExtrinsicPayloadV3 | ExtrinsicPayloadV4; -const VERSIONS: InterfaceTypes[] = [ +const VERSIONS: (keyof InterfaceTypes)[] = [ 'ExtrinsicPayloadUnknown', // v0 is unknown 'ExtrinsicPayloadV1', 'ExtrinsicPayloadV2', diff --git a/packages/types/src/extrinsic/signedExtensions/types.ts b/packages/types/src/extrinsic/signedExtensions/types.ts index fe0ca24abe..ea5db5c4ea 100644 --- a/packages/types/src/extrinsic/signedExtensions/types.ts +++ b/packages/types/src/extrinsic/signedExtensions/types.ts @@ -4,7 +4,7 @@ import { InterfaceTypes } from '../../types'; -export type ExtTypes = Record; +export type ExtTypes = Record; export type ExtInfo = { extra: ExtTypes; diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts deleted file mode 100644 index 3f5c87d456..0000000000 --- a/packages/types/src/interfaceRegistry.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2017-2020 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface InterfaceRegistry { } diff --git a/packages/types/src/types/helpers.ts b/packages/types/src/types/helpers.ts index fe3ddb7442..e142b1ed5e 100644 --- a/packages/types/src/types/helpers.ts +++ b/packages/types/src/types/helpers.ts @@ -2,12 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry'; - import BN from 'bn.js'; -export type InterfaceTypes = keyof InterfaceRegistry; - // We cannot inline this into CodecArg, TS thrws up when building docs // eslint-disable-next-line @typescript-eslint/no-explicit-any export type AnyFunction = (...args: any[]) => any; diff --git a/packages/types/src/types/registry.ts b/packages/types/src/types/registry.ts index 13cb3b94aa..b377a085d7 100644 --- a/packages/types/src/types/registry.ts +++ b/packages/types/src/types/registry.ts @@ -8,7 +8,10 @@ import BN from 'bn.js'; import { CallFunction } from './calls'; import { Codec, Constructor } from './codec'; -import { AnyJson, InterfaceTypes } from './helpers'; +import { AnyJson } from './helpers'; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface InterfaceTypes { } export type RegistryTypes = Record | { _enum: string[] | Record } | { _set: Record }>; @@ -94,8 +97,8 @@ export interface Registry { getDefinition (name: string): string | undefined; getOrThrow (name: string, msg?: string): Constructor; getOrUnknown (name: string): Constructor; - getSignedExtensionExtra (): Record; - getSignedExtensionTypes (): Record; + getSignedExtensionExtra (): Record; + getSignedExtensionTypes (): Record; hasClass (name: string): boolean; hasDef (name: string): boolean; hasType (name: string): boolean;