Move Metadata to interfaces (#1598)

* Move Metadata to interfaces

* Align imports

* Suppress errors

* Remove TS overrides, createTypeUnsafe returns Codec

* Add type unwrap

* Fixup doc generation

* Remove V8 references
This commit is contained in:
Jaco Greeff
2019-11-22 13:38:20 +01:00
committed by GitHub
parent 4b6b0305e6
commit 8b1a7a8584
42 changed files with 644 additions and 1396 deletions
@@ -1,85 +0,0 @@
// Copyright 2017-2019 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventMetadataV7, FunctionMetadataV7, ModuleConstantMetadataV7 } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import { MetadataInterface } from '../types';
import Option from '@polkadot/types/codec/Option';
import Struct from '@polkadot/types/codec/Struct';
import Vec from '@polkadot/types/codec/Vec';
import Text from '@polkadot/types/primitive/Text';
import { StorageMetadata } from './Storage';
/**
* @name ModuleMetadataV7
* @description
* The definition of a module in the system
*/
export class ModuleMetadataV7 extends Struct {
constructor (registry: Registry, value?: any) {
super(registry, {
name: 'Text',
storage: Option.with(StorageMetadata),
calls: Option.with('Vec<FunctionMetadataV7>'),
events: Option.with('Vec<EventMetadataV7>'),
constants: 'Vec<ModuleConstantMetadataV7>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV7>> {
return this.get('calls') as Option<Vec<FunctionMetadataV7>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV7> {
return this.get('constants') as Vec<ModuleConstantMetadataV7>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV7>> {
return this.get('events') as Option<Vec<EventMetadataV7>>;
}
/**
* @description the module name
*/
public get name (): Text {
return this.get('name') as Text;
}
/**
* @description the associated module storage
*/
public get storage (): Option<StorageMetadata> {
return this.get('storage') as Option<StorageMetadata>;
}
}
/**
* @name MetadataV7
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadataV7> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV7)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV7> {
return this.get('modules') as Vec<ModuleMetadataV7>;
}
}
@@ -1,41 +0,0 @@
// Copyright 2017-2019 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Registry } from '@polkadot/types/types';
import Struct from '@polkadot/types/codec/Struct';
import Vec from '@polkadot/types/codec/Vec';
import Text from '@polkadot/types/primitive/Text';
import { StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryType } from '../v6/Storage';
// Re-export classes that haven't changed between V6 and V7
export {
StorageEntryMetadata,
StorageEntryMetadataValue,
StorageEntryType
};
export class StorageMetadata extends Struct {
constructor (registry: Registry, value?: any) {
super(registry, {
prefix: 'Text',
// NOTE renamed to items from entries (since Struct already has entries from Map)
items: Vec.with(StorageEntryMetadata)
}, value);
}
/**
* @description the storage entries
*/
public get items (): Vec<StorageEntryMetadata> {
return this.get('items') as Vec<StorageEntryMetadata>;
}
/**
* @description the prefix for this module
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
}
@@ -1,11 +0,0 @@
// Copyright 2017-2019 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import MetadataV7, { ModuleMetadataV7 } from './Metadata';
export default MetadataV7;
export {
ModuleMetadataV7
};
+4 -5
View File
@@ -2,19 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { MetadataV7, MetadataV8, ModuleMetadataV8 } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import MetadataV7 from './Metadata';
import MetadataV8 from '../v8';
import { ModuleMetadataV8 } from '../v8/Metadata';
import { createType } from '@polkadot/types';
/**
* Convert from MetadataV7 to MetadataV8
*/
export default function toV8 (registry: Registry, { modules }: MetadataV7): MetadataV8 {
return new MetadataV8(registry, {
return createType(registry, 'MetadataV8', {
modules: modules.map(({ calls, constants, events, name, storage }): ModuleMetadataV8 =>
new ModuleMetadataV8(registry, {
createType(registry, 'ModuleMetadataV8', {
calls,
constants,
errors: [],