Mark some function @internal (no doc extraction) (#1746)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// Quick and dirty flatten (.flat() not available)
|
||||
/** @internal */
|
||||
export default function flattenUniq (list: any[]): any[] {
|
||||
const flat = list.reduce((result, entry): any[] => {
|
||||
return result.concat(
|
||||
|
||||
@@ -69,6 +69,7 @@ interface ExtractionMetadata {
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function unwrapCalls (mod: Module): Call[] {
|
||||
return mod.calls
|
||||
? mod.calls.unwrapOr([])
|
||||
@@ -78,6 +79,7 @@ function unwrapCalls (mod: Module): Call[] {
|
||||
: [];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getCallNames ({ modules }: ExtractionMetadata): string[][][] {
|
||||
return modules.map((mod): string[][] =>
|
||||
unwrapCalls(mod).map(({ args }): string[] =>
|
||||
@@ -88,6 +90,7 @@ function getCallNames ({ modules }: ExtractionMetadata): string[][][] {
|
||||
);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getConstantNames ({ modules }: ExtractionMetadata): string[][] {
|
||||
return modules.map(({ constants }): string[] =>
|
||||
constants
|
||||
@@ -98,6 +101,7 @@ function getConstantNames ({ modules }: ExtractionMetadata): string[][] {
|
||||
);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function unwrapEvents (events?: Events): Event[] {
|
||||
if (!events) {
|
||||
return [];
|
||||
@@ -106,6 +110,7 @@ function unwrapEvents (events?: Events): Event[] {
|
||||
return events.unwrapOr([]);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getEventNames ({ modules, outerEvent }: ExtractionMetadata): string[][][] {
|
||||
const mapArg = ({ args }: Event): string[] =>
|
||||
args.map((arg): string =>
|
||||
@@ -125,6 +130,7 @@ function getEventNames ({ modules, outerEvent }: ExtractionMetadata): string[][]
|
||||
);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function unwrapStorage (storage?: Storage): Item[] {
|
||||
if (!storage) {
|
||||
return [];
|
||||
@@ -137,6 +143,7 @@ function unwrapStorage (storage?: Storage): Item[] {
|
||||
: (data.items || data.functions) as Item[];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getStorageNames ({ modules }: ExtractionMetadata): string[][][] {
|
||||
return modules.map(({ storage }): string[][] =>
|
||||
unwrapStorage(storage).map(({ type }): string[] => {
|
||||
@@ -160,6 +167,7 @@ function getStorageNames ({ modules }: ExtractionMetadata): string[][][] {
|
||||
);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export default function getUniqTypes (registry: Registry, meta: ExtractionMetadata, throwError: boolean): string[] {
|
||||
const types = flattenUniq([
|
||||
getCallNames(meta),
|
||||
|
||||
@@ -11,10 +11,7 @@ import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import getUniqTypes from './getUniqTypes';
|
||||
import Metadata from '../Metadata';
|
||||
|
||||
/**
|
||||
* Given the static `rpcData` and the `staticSubstrate` JSON file, Metadata
|
||||
* should decode `rpcData` and output `staticSubstrate`.
|
||||
*/
|
||||
/** @internal */
|
||||
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: object): void {
|
||||
it('decodes latest substrate properly', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
@@ -31,10 +28,7 @@ export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a `version`, MetadataLatest and MetadataV{version} should output the same
|
||||
* unique types.
|
||||
*/
|
||||
/** @internal */
|
||||
export function toLatest<Modules extends Codec> (registry: Registry, version: number, rpcData: string): void {
|
||||
it(`converts v${version} to latest`, (): void => {
|
||||
const metadata = new Metadata(registry, rpcData)[`asV${version}` as keyof Metadata];
|
||||
@@ -48,9 +42,7 @@ export function toLatest<Modules extends Codec> (registry: Registry, version: nu
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a Metadata, no type should throw when given its fallback value.
|
||||
*/
|
||||
/** @internal */
|
||||
export function defaultValues (registry: Registry, rpcData: string): void {
|
||||
describe('storage with default values', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
|
||||
@@ -7,9 +7,7 @@ import { AnyJsonObject, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* @description Convert from MetadataLatest to a stripped representation of MetadataLatest
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toCallsOnly (registry: Registry, { modules }: MetadataLatest): AnyJsonObject | string {
|
||||
return createType(registry, 'MetadataLatest', {
|
||||
// FIXME, this needs typing, not any
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getTypeDef } from '@polkadot/types/codec/create';
|
||||
|
||||
import flattenUniq from './flattenUniq';
|
||||
|
||||
/** @internal */
|
||||
function extractTypes (types: string[]): any[] {
|
||||
return types.map((type): any => {
|
||||
const decoded = getTypeDef(type);
|
||||
@@ -37,6 +38,7 @@ function extractTypes (types: string[]): any[] {
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export default function validateTypes (registry: Registry, types: string[], throwError: boolean): void {
|
||||
const missing = flattenUniq(extractTypes(types)).filter((type): boolean =>
|
||||
!registry.hasType(type)
|
||||
|
||||
@@ -11,12 +11,14 @@ import { stringUpperFirst } from '@polkadot/util';
|
||||
import { createType, Option, Vec } from '@polkadot/types/codec';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
|
||||
/** @internal */
|
||||
function toV1Calls (registry: Registry, { module: { call: { functions } } }: RuntimeModuleMetadataV0): Option<FunctionMetadataV1> {
|
||||
return functions.length
|
||||
? new Option(registry, Vec.with('FunctionMetadataV1'), functions)
|
||||
: new Option(registry, Vec.with('FunctionMetadataV1'));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function toV1Events (registry: Registry, metadataV0: MetadataV0, prefix: Text): Option<EventMetadataV1> {
|
||||
const events = metadataV0.outerEvent.events.find((event): boolean => event[0].eq(prefix));
|
||||
|
||||
@@ -25,15 +27,14 @@ function toV1Events (registry: Registry, metadataV0: MetadataV0, prefix: Text):
|
||||
: new Option(registry, Vec.with('EventMetadataV1'));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function toV1Storage (registry: Registry, { storage }: RuntimeModuleMetadataV0): Option<StorageFunctionMetadataV1> {
|
||||
return storage.isSome
|
||||
? new Option(registry, 'Vec<StorageFunctionMetadataV1>', storage.unwrap().functions)
|
||||
: new Option(registry, 'Vec<StorageFunctionMetadataV1>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that converts MetadataV0 to MetadataV1
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV1 (registry: Registry, metadataV0: MetadataV0): MetadataV1 {
|
||||
return createType(registry, 'MetadataV1', {
|
||||
modules: metadataV0.modules.map((mod): ModuleMetadataV1 => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/** @internal */
|
||||
export default function toV2 (registry: Registry, metadataV1: MetadataV1): MetadataV2 {
|
||||
return createType(registry, 'MetadataV2', metadataV1);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
// migrate a storage entry type - only map types are different (with a kind enum)
|
||||
// all return the actual value for the enum, followed by the numeric index
|
||||
/** @internal */
|
||||
function createStorageType (registry: Registry, entryType: StorageEntryTypeV10): [any, number] {
|
||||
if (entryType.isPlain) {
|
||||
return [entryType.asPlain, 0];
|
||||
@@ -29,6 +30,7 @@ function createStorageType (registry: Registry, entryType: StorageEntryTypeV10):
|
||||
}
|
||||
|
||||
// apply module-specific type overrides
|
||||
/** @internal */
|
||||
function convertCalls (registry: Registry, calls: FunctionMetadataV10[], sectionTypes: OverrideModuleType[]): FunctionMetadataV11[] {
|
||||
return calls.map(({ args, documentation, name }): FunctionMetadataV11 => {
|
||||
args.forEach(({ type }): void => {
|
||||
@@ -43,6 +45,7 @@ function convertCalls (registry: Registry, calls: FunctionMetadataV10[], section
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetadataV11 {
|
||||
const calls = mod.calls.unwrapOr(null);
|
||||
const storage = mod.storage.unwrapOr(null);
|
||||
@@ -65,9 +68,7 @@ function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetad
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from MetadataV10 to MetadataV11
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV11 (registry: Registry, { modules }: MetadataV10): MetadataV11 {
|
||||
return createType(registry, 'MetadataV11', {
|
||||
modules: modules.map((mod): ModuleMetadataV11 => convertModule(registry, mod))
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/** @internal */
|
||||
export default function toV3 (registry: Registry, metadataV2: MetadataV2): MetadataV3 {
|
||||
return createType(registry, 'MetadataV3', metadataV2);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType, Option } from '@polkadot/types/codec';
|
||||
|
||||
/**
|
||||
* Convert V3 StorageFunction to V4 StorageFunction
|
||||
*/
|
||||
/** @internal */
|
||||
function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV3): StorageFunctionMetadataV4 {
|
||||
const { documentation, fallback, modifier, name, type } = storageFn;
|
||||
|
||||
@@ -42,10 +40,7 @@ function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMeta
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from MetadataV3 to MetadataV4
|
||||
* See https://github.com/paritytech/substrate/pull/2268 for details
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV4 (registry: Registry, { modules }: MetadataV3): MetadataV4 {
|
||||
return createType(registry, 'MetadataV4', {
|
||||
modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV4 =>
|
||||
|
||||
@@ -18,6 +18,7 @@ const hasherMap: Map<string, string> = new Map([
|
||||
['twox_64_concat', 'Twox64Concat']
|
||||
]);
|
||||
|
||||
/** @internal */
|
||||
function toStorageHasher (registry: Registry, text: Text): StorageHasherV5 {
|
||||
const mapped = hasherMap.get(text.toString());
|
||||
|
||||
@@ -26,9 +27,7 @@ function toStorageHasher (registry: Registry, text: Text): StorageHasherV5 {
|
||||
return createType(registry, 'StorageHasherV5', mapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert V4 StorageFunction to V5 StorageFunction
|
||||
*/
|
||||
/** @internal */
|
||||
function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV4): StorageFunctionMetadataV5 {
|
||||
const { documentation, fallback, modifier, name, type } = storageFn;
|
||||
const [newType, index] = type.isPlain
|
||||
@@ -52,10 +51,7 @@ function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMeta
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from MetadataV4 to MetadataV5
|
||||
* See https://github.com/paritytech/substrate/pull/2836/files for details
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV5 (registry: Registry, { modules }: MetadataV4): MetadataV5 {
|
||||
return createType(registry, 'MetadataV5', {
|
||||
modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV5 =>
|
||||
|
||||
@@ -7,10 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV5 to MetadataV6
|
||||
* See https://github.com/polkadot-js/api/issues/1043 for details
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV6 (registry: Registry, { modules }: MetadataV5): MetadataV6 {
|
||||
return createType(registry, 'MetadataV6', {
|
||||
modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV6 =>
|
||||
|
||||
@@ -7,9 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV6 to MetadataV7
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV7 (registry: Registry, { modules }: MetadataV6): MetadataV7 {
|
||||
return createType(registry, 'MetadataV7', {
|
||||
modules: modules.map(({ calls, constants, events, name, prefix, storage }): ModuleMetadataV7 =>
|
||||
|
||||
@@ -7,9 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV7 to MetadataV8
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV8 (registry: Registry, { modules }: MetadataV7): MetadataV8 {
|
||||
return createType(registry, 'MetadataV8', {
|
||||
modules: modules.map(({ calls, constants, events, name, storage }): ModuleMetadataV8 =>
|
||||
|
||||
@@ -7,9 +7,7 @@ import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV8 to MetadataV9
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV9 (registry: Registry, { modules }: MetadataV8): MetadataV9 {
|
||||
return createType(registry, 'MetadataV9', { modules });
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createType } from '@polkadot/types';
|
||||
|
||||
// migrate a storage hasher type
|
||||
// see https://github.com/paritytech/substrate/pull/4462
|
||||
/** @internal */
|
||||
function createStorageHasher (registry: Registry, hasher: StorageHasherV9): StorageHasherV10 {
|
||||
// Blake2_128_Concat has been added at index 2, so we increment all the
|
||||
// indexes greater than 2
|
||||
@@ -19,6 +20,7 @@ function createStorageHasher (registry: Registry, hasher: StorageHasherV9): Stor
|
||||
return createType(registry, 'StorageHasherV10', hasher);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function createStorageType (registry: Registry, entryType: StorageEntryTypeV9): [any, number] {
|
||||
if (entryType.isMap) {
|
||||
return [{
|
||||
@@ -38,6 +40,7 @@ function createStorageType (registry: Registry, entryType: StorageEntryTypeV9):
|
||||
return [entryType.asPlain, 0];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function convertModule (registry: Registry, mod: ModuleMetadataV9): ModuleMetadataV10 {
|
||||
const storage = mod.storage.unwrapOr(null);
|
||||
|
||||
@@ -55,9 +58,7 @@ function convertModule (registry: Registry, mod: ModuleMetadataV9): ModuleMetada
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from MetadataV9 to MetadataV10
|
||||
*/
|
||||
/** @internal */
|
||||
export default function toV10 (registry: Registry, { modules }: MetadataV9): MetadataV10 {
|
||||
return createType(registry, 'MetadataV10', {
|
||||
modules: modules.map((mod): ModuleMetadataV10 => convertModule(registry, mod))
|
||||
|
||||
Reference in New Issue
Block a user