Mark some function @internal (no doc extraction) (#1746)
This commit is contained in:
@@ -38,6 +38,7 @@ export type DeriveCustom = Record<string, Record<string, (api: ApiInterfaceRx) =
|
||||
* Returns an object that will inject `api` into all the functions inside
|
||||
* `allSections`, and keep the object architecture of `allSections`.
|
||||
*/
|
||||
/** @internal */
|
||||
function injectFunctions<AllSections> (api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections<AllSections> {
|
||||
return Object
|
||||
.keys(allSections)
|
||||
@@ -65,6 +66,7 @@ export type ExactDerive = DeriveAllSections<typeof derive>;
|
||||
|
||||
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
|
||||
// For now we just drop the custom derive typings
|
||||
/** @internal */
|
||||
export default function decorateDerive (api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
|
||||
return {
|
||||
...injectFunctions(api, derive),
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ApprovalFlag } from '@polkadot/types/interfaces/elections';
|
||||
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
/** @internal */
|
||||
export function approvalFlagsToBools (flags: Vec<ApprovalFlag> | ApprovalFlag[]): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ const normalizer = JSON.stringify;
|
||||
// Wraps a derive, doing 2 things to optimize calls -
|
||||
// 1. creates a memo of the inner fn -> Observable, removing when unsubscribed
|
||||
// 2. wraps the observable in a drr() (which includes an unsub delay)
|
||||
/** @internal */
|
||||
export function memo <T> (inner: ObsFn<T>): ObsFn<T> {
|
||||
const cached = createMemo(
|
||||
(...params: any[]): Observable<T> =>
|
||||
|
||||
@@ -12,11 +12,7 @@ import Metadata from '../../../Metadata';
|
||||
|
||||
const AS_STRIPPED = ['Bytes'];
|
||||
|
||||
/**
|
||||
* Retrieve the parameter types (module constants) from the runtime metadata.
|
||||
*
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
/** @internal */
|
||||
export default function fromMetadata (registry: Registry, metadata: Metadata): Constants {
|
||||
return metadata.asLatest.modules.reduce((result: Constants, moduleMetadata): Constants => {
|
||||
if (moduleMetadata.constants.isEmpty) {
|
||||
|
||||
@@ -10,15 +10,7 @@ import { AnyJsonObject, CallFunction, Registry, RegistryMetadataCall } from '@po
|
||||
import { createType } from '@polkadot/types/codec/create/createType';
|
||||
import { assert, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
/**
|
||||
* From the metadata of a function in the module's storage, generate the function
|
||||
* that will return the an [[CallFunction]].
|
||||
*
|
||||
* @param section - Name of the module section.
|
||||
* @param sectionIndex - Index of the module section in the modules array.
|
||||
* @param methodIndex - Index of the method inside the section.
|
||||
* @param callMetadata - Metadata of the call function.
|
||||
*/
|
||||
/** @internal */
|
||||
export default function createDescriptor (registry: Registry, section: string, sectionIndex: number, methodIndex: number, callMetadata: RegistryMetadataCall): CallFunction {
|
||||
const callIndex = new Uint8Array([sectionIndex, methodIndex]);
|
||||
const expectedArgs = callMetadata.args;
|
||||
|
||||
@@ -9,11 +9,7 @@ import { stringCamelCase } from '@polkadot/util';
|
||||
import extrinsics from '../';
|
||||
import createUnchecked from './createUnchecked';
|
||||
|
||||
/**
|
||||
* Return an object with the modules and the functions to use extrinsics.
|
||||
*
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
/** @internal */
|
||||
export default function fromMetadata (registry: Registry, metadata: RegistryMetadata): ModulesWithCalls {
|
||||
return metadata.asLatest.modules
|
||||
.filter(({ calls }): boolean => calls.isSome)
|
||||
|
||||
@@ -37,6 +37,7 @@ const EMPTY_U8A = new Uint8Array([]);
|
||||
const NULL_HASHER = (value: Uint8Array): Uint8Array => value;
|
||||
|
||||
// with the prefix, method & options, create both the string & raw keys
|
||||
/** @internal */
|
||||
function expandKey ({ method, prefix }: CreateItemFn, options: CreateItemOptions): string {
|
||||
return options.key
|
||||
? options.key
|
||||
@@ -44,6 +45,7 @@ function expandKey ({ method, prefix }: CreateItemFn, options: CreateItemOptions
|
||||
}
|
||||
|
||||
// get the hashers, the base (and in the case of DoubleMap), the second key
|
||||
/** @internal */
|
||||
function getHashers ({ meta: { type } }: CreateItemFn): [HasherFunction, HasherFunction?] {
|
||||
if (type.isDoubleMap) {
|
||||
return [
|
||||
@@ -59,11 +61,13 @@ function getHashers ({ meta: { type } }: CreateItemFn): [HasherFunction, HasherF
|
||||
}
|
||||
|
||||
// create a base prefixed key
|
||||
/** @internal */
|
||||
function createPrefixedKey ({ method, prefix }: CreateItemFn): Uint8Array {
|
||||
return u8aConcat(xxhashAsU8a(prefix, 128), xxhashAsU8a(method, 128));
|
||||
}
|
||||
|
||||
// create a key for a DoubleMap type
|
||||
/** @internal */
|
||||
function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, stringKey: string, args: [CreateArgType, CreateArgType], [hasher1, hasher2]: [HasherFunction, HasherFunction?], metaVersion: number): Uint8Array {
|
||||
const { meta: { name, type } } = itemFn;
|
||||
|
||||
@@ -97,6 +101,7 @@ function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, stringKey
|
||||
}
|
||||
|
||||
// create a key for either a map or a plain value
|
||||
/** @internal */
|
||||
function createKey (registry: Registry, itemFn: CreateItemFn, stringKey: string, arg: CreateArgType, hasher: (value: Uint8Array) => Uint8Array, metaVersion: number): Uint8Array {
|
||||
const { meta: { name, type } } = itemFn;
|
||||
let key: Uint8Array | undefined;
|
||||
@@ -126,6 +131,7 @@ function createKey (registry: Registry, itemFn: CreateItemFn, stringKey: string,
|
||||
}
|
||||
|
||||
// attach the metadata to expand to a StorageFunction
|
||||
/** @internal */
|
||||
function expandWithMeta ({ meta, method, prefix, section }: CreateItemFn, storageFn: StorageEntry): StorageEntry {
|
||||
storageFn.meta = meta;
|
||||
storageFn.method = stringLowerFirst(method);
|
||||
@@ -142,6 +148,7 @@ function expandWithMeta ({ meta, method, prefix, section }: CreateItemFn, storag
|
||||
return storageFn;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function extendHeadMeta (registry: Registry, { meta: { documentation, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: () => Raw): StorageKey {
|
||||
const map = type.asMap;
|
||||
const outputType = map.key.toString();
|
||||
@@ -160,6 +167,7 @@ function extendHeadMeta (registry: Registry, { meta: { documentation, name, type
|
||||
}
|
||||
|
||||
// attach the head key hashing for linked maps
|
||||
/** @internal */
|
||||
function extendLinkedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry, stringKey: string, hasher: HasherFunction, metaVersion: number): StorageEntry {
|
||||
const key = metaVersion <= 8
|
||||
? hasher(`head of ${stringKey}`)
|
||||
@@ -173,6 +181,7 @@ function extendLinkedMap (registry: Registry, itemFn: CreateItemFn, storageFn: S
|
||||
}
|
||||
|
||||
// attach the full list hashing for prefixed maps
|
||||
/** @internal */
|
||||
function extendPrefixedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry): StorageEntry {
|
||||
storageFn.iterKey = extendHeadMeta(registry, itemFn, storageFn, (): Raw =>
|
||||
new Raw(registry, createPrefixedKey(itemFn))
|
||||
@@ -181,16 +190,7 @@ function extendPrefixedMap (registry: Registry, itemFn: CreateItemFn, storageFn:
|
||||
return storageFn;
|
||||
}
|
||||
|
||||
/**
|
||||
* From the schema of a function in the module's storage, generate the function
|
||||
* that will return the correct storage key.
|
||||
*
|
||||
* @param item - The function's definition schema to create the function from.
|
||||
* The schema is taken from state_getMetadata.
|
||||
* @param options - Additional options when creating the function. These options
|
||||
* are not known at runtime (from state_getMetadata), they need to be supplied
|
||||
* by us manually at compile time.
|
||||
*/
|
||||
/** @internal */
|
||||
export default function createFunction (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
|
||||
const { meta: { type } } = itemFn;
|
||||
const stringKey = expandKey(itemFn, options);
|
||||
|
||||
@@ -23,6 +23,7 @@ const map: Record<HasherCheck, HasherFunction> = {
|
||||
isTwox64Concat: (data: HasherInput): Uint8Array => u8aConcat(xxhashAsU8a(data, 64), u8aToU8a(data))
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export default function getHasher (hasher?: StorageHasher): HasherFunction {
|
||||
const [, fn] = (hasher && Object.entries(map).find(([check]): boolean =>
|
||||
hasher[check as HasherCheck]
|
||||
|
||||
@@ -11,11 +11,7 @@ import Metadata from '../../../Metadata';
|
||||
import createFunction from './createFunction';
|
||||
import getStorage from './storage';
|
||||
|
||||
/**
|
||||
* Return an object with the modules and the functions to access their storage.
|
||||
*
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
/** @internal */
|
||||
export default function fromMetadata (registry: Registry, metadata: Metadata): Storage {
|
||||
return metadata.asLatest.modules.reduce((result, moduleMetadata): Storage => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Storage } from '../../types';
|
||||
|
||||
import * as substrate from './substrate';
|
||||
|
||||
/** @internal */
|
||||
export default function getStorage (registry: Registry, metaVersion: number): Storage {
|
||||
return {
|
||||
substrate: Object
|
||||
|
||||
@@ -16,6 +16,7 @@ interface SubstrateMetadata {
|
||||
}
|
||||
|
||||
// Small helper function to factorize code on this page.
|
||||
/** @internal */
|
||||
function createRuntimeFunction (method: string, key: string, { documentation, type }: SubstrateMetadata): (registry: Registry, metaVersion: number) => StorageEntry {
|
||||
return (registry: Registry, metaVersion: number): StorageEntry =>
|
||||
createFunction(registry, {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -34,6 +34,7 @@ const EMPTY_META = {
|
||||
};
|
||||
|
||||
// utility method to create a nicely-formatted error
|
||||
/** @internal */
|
||||
function createErrorMessage ({ method, params, type }: RpcMethod, error: Error): string {
|
||||
const inputs = params.map(({ isOptional, name, type }): string =>
|
||||
`${name}${isOptional ? '?' : ''}: ${type}`
|
||||
|
||||
@@ -32,6 +32,7 @@ const NOOP = (): void => undefined;
|
||||
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
||||
*
|
||||
* @ignore
|
||||
* @internal
|
||||
*/
|
||||
export const drr = ({ skipChange = false, skipTimeout = false }: Options = {}): DrrResult => <T> (source$: Observable<T>): Observable<T> =>
|
||||
source$.pipe(
|
||||
|
||||
@@ -6,6 +6,7 @@ import { asapScheduler, ConnectableObservable, MonoTypeOperatorFunction, Observa
|
||||
|
||||
const DELAY = 1750;
|
||||
|
||||
/** @internal */
|
||||
function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
|
||||
let connected = 0; // 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
||||
let refCount = 0;
|
||||
@@ -43,6 +44,7 @@ function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function refCountDelay <T> (): MonoTypeOperatorFunction<T> {
|
||||
return refCountDelayInner;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { JsonRpcRequest, JsonRpcResponse, JsonRpcResponseBaseError } from '../ty
|
||||
|
||||
import { assert, isUndefined, isNumber, isString } from '@polkadot/util';
|
||||
|
||||
/** @internal */
|
||||
export default class RpcCoder {
|
||||
private id = 0;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ const l = logger('api-mock');
|
||||
/**
|
||||
* A mock provider mainly used for testing.
|
||||
* @return {ProviderInterface} The mock provider
|
||||
* @internal
|
||||
*/
|
||||
export default class Mock implements ProviderInterface {
|
||||
private db: MockStateDb = {};
|
||||
|
||||
@@ -12,6 +12,7 @@ import { isUndefined } from '@polkadot/util';
|
||||
import { TYPES_CHAIN, TYPES_META, TYPES_MODULES, TYPES_SPEC } from './overrides';
|
||||
|
||||
// flatten a VersionedType[] into a Record<string, string>
|
||||
/** @internal */
|
||||
function filterVersions (versions: OverrideVersionedType[] = [], version: number): RegistryTypes {
|
||||
return versions
|
||||
.filter(({ minmax: [min, max] }): boolean =>
|
||||
@@ -25,11 +26,13 @@ function filterVersions (versions: OverrideVersionedType[] = [], version: number
|
||||
}
|
||||
|
||||
// based on the metadata version, return the registry types
|
||||
/** @internal */
|
||||
export function getMetadataTypes (version: number): RegistryTypes {
|
||||
return filterVersions(TYPES_META, version);
|
||||
}
|
||||
|
||||
// based on the chain and runtimeVersion, get the applicable types (ready for registration)
|
||||
/** @internal */
|
||||
export function getChainTypes (chainName: Text, { specName, specVersion }: RuntimeVersion, typesChain: Record<string, RegistryTypes> = {}, typesSpec: Record<string, RegistryTypes> = {}): RegistryTypes {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
@@ -44,6 +47,7 @@ export function getChainTypes (chainName: Text, { specName, specVersion }: Runti
|
||||
}
|
||||
|
||||
// get types for specific modules (metadata override)
|
||||
/** @internal */
|
||||
export function getModuleTypes (section: string): OverrideModuleType[] {
|
||||
return TYPES_MODULES[section] || [];
|
||||
}
|
||||
|
||||
@@ -25,14 +25,17 @@ const DESC_EVENTS = `\n\nEvents are emitted for certain operations on the runtim
|
||||
const DESC_RPC = '\n\nThe following sections contain RPC methods that are Remote Calls available by default and allow you to interact with the actual node, query, and submit.\n';
|
||||
const DESC_STORAGE = `\n\nThe following sections contain Storage methods are part of the default Substrate runtime. On the api, these are exposed via \`api.query.<module>.<method>\`. ${STATIC_TEXT}\n`;
|
||||
|
||||
/** @internal */
|
||||
function sectionLink (sectionName: string): string {
|
||||
return `- **[${stringCamelCase(sectionName)}](#${stringCamelCase(sectionName)})**\n\n`;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function generateSectionHeader (md: string, sectionName: string): string {
|
||||
return `${md}\n___\n${LINK_BACK_TO_TOP}\n\n## ${sectionName}\n`;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addRpc (): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}JSON-RPC${DESC_RPC}\n`;
|
||||
const orderedSections = Object.keys(interfaces).sort();
|
||||
@@ -60,6 +63,7 @@ function addRpc (): string {
|
||||
/**
|
||||
* Sort object by their `.name`
|
||||
*/
|
||||
/** @internal */
|
||||
function sortByName<T extends { name: any }> (a: T, b: T): number {
|
||||
// ignore upper and lowercase
|
||||
const nameA = a.name.toString().toUpperCase();
|
||||
@@ -68,6 +72,7 @@ function sortByName<T extends { name: any }> (a: T, b: T): number {
|
||||
return nameA.localeCompare(nameB);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addConstants (metadata: MetadataLatest): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Constants${DESC_CONSTANTS}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
@@ -96,6 +101,7 @@ function addConstants (metadata: MetadataLatest): string {
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addEvents (metadata: MetadataLatest): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
@@ -126,6 +132,7 @@ function addEvents (metadata: MetadataLatest): string {
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addExtrinsics (metadata: MetadataLatest): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`;
|
||||
const orderedSections = metadata.modules.map((i): ModuleMetadataLatest => i).sort(sortByName);
|
||||
@@ -156,6 +163,7 @@ function addExtrinsics (metadata: MetadataLatest): string {
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addStorage (metadata: MetadataLatest): string {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
@@ -196,6 +204,7 @@ function addStorage (metadata: MetadataLatest): string {
|
||||
return renderHeading + renderAnchors + sectionLink('substrate') + sections;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeFile (name: string, ...chunks: any[]): void {
|
||||
const options = { flags: 'w', encoding: 'utf8' };
|
||||
const writeStream = fs.createWriteStream(name, options);
|
||||
@@ -211,14 +220,17 @@ function writeFile (name: string, ...chunks: any[]): void {
|
||||
writeStream.end();
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToRpcMd (): void {
|
||||
writeFile('docs/substrate/rpc.md', addRpc());
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToConstantsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/constants.md', addConstants(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToStorageMd (metadata: MetadataLatest): void {
|
||||
const options = { flags: 'r', encoding: 'utf8' };
|
||||
const data = fs.readFileSync('docs/substrate/storage-known.md', options);
|
||||
@@ -226,10 +238,12 @@ function writeToStorageMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/storage.md', addStorage(metadata), data);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToExtrinsicsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/extrinsics.md', addExtrinsics(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToEventsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/events.md', addEvents(metadata));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ const { argv: { ws } } = yargs
|
||||
}
|
||||
});
|
||||
|
||||
/** @internal */
|
||||
async function main (): Promise<void> {
|
||||
const provider = new WsProvider(ws);
|
||||
const api = await ApiPromise.create({ provider });
|
||||
|
||||
@@ -13,6 +13,7 @@ import { Metadata, TypeRegistry } from '../..';
|
||||
import { createImportCode, createImports, FOOTER, HEADER, indent, setImports, TypeImports } from '../util';
|
||||
|
||||
// Generate types for one module
|
||||
/** @internal */
|
||||
function generateModule (modul: ModuleMetadataLatest, imports: TypeImports): string[] {
|
||||
if (!modul.constants.length) {
|
||||
return [];
|
||||
@@ -35,6 +36,7 @@ function generateModule (modul: ModuleMetadataLatest, imports: TypeImports): str
|
||||
|
||||
// Generate `packages/api/src/consts.types.ts` for a particular
|
||||
// metadata
|
||||
/** @internal */
|
||||
function generateForMeta (meta: Metadata): void {
|
||||
console.log('Writing packages/api/src/consts.types.ts');
|
||||
|
||||
@@ -84,6 +86,7 @@ function generateForMeta (meta: Metadata): void {
|
||||
}
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export default function generateConsts (): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ const primitiveClasses = {
|
||||
Raw
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export function generateInterfaceRegistry (importDefinitions: { [importPath: string]: object }, output: string): void {
|
||||
console.log(`Writing ${output}`);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { TypeRegistry } from '../../codec';
|
||||
import { createImportCode, createImports, FOOTER, formatType, getSimilarTypes, HEADER, indent, setImports, TypeImports } from '../util';
|
||||
|
||||
// If the StorageEntry returns T, output `Option<T>` if the modifier is optional
|
||||
/** @internal */
|
||||
function addModifier (storageEntry: StorageEntryMetadataLatest, returnType: string): string {
|
||||
if (storageEntry.modifier.isOptional) {
|
||||
return `Option<${returnType}>`;
|
||||
@@ -24,6 +25,7 @@ function addModifier (storageEntry: StorageEntryMetadataLatest, returnType: stri
|
||||
}
|
||||
|
||||
// From a storage entry metadata, we return [args, returnType]
|
||||
/** @internal */
|
||||
function entrySignature (definitions: object, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [string, string] {
|
||||
if (storageEntry.type.isPlain) {
|
||||
setImports(definitions, imports, [storageEntry.type.asPlain.toString()]);
|
||||
@@ -66,6 +68,7 @@ function entrySignature (definitions: object, registry: Registry, storageEntry:
|
||||
}
|
||||
|
||||
// Generate types for one storage entry in a module
|
||||
/** @internal */
|
||||
function generateEntry (definitions: object, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): string[] {
|
||||
const [args, returnType] = entrySignature(definitions, registry, storageEntry, imports);
|
||||
|
||||
@@ -75,6 +78,7 @@ function generateEntry (definitions: object, registry: Registry, storageEntry: S
|
||||
}
|
||||
|
||||
// Generate types for one module
|
||||
/** @internal */
|
||||
function generateModule (definitions: object, registry: Registry, modul: ModuleMetadataLatest, imports: TypeImports): string[] {
|
||||
if (modul.storage.isNone) {
|
||||
return [];
|
||||
@@ -94,6 +98,7 @@ function generateModule (definitions: object, registry: Registry, modul: ModuleM
|
||||
|
||||
// Generate `packages/api/src/query.types.ts` for a particular
|
||||
// metadata
|
||||
/** @internal */
|
||||
function generateForMeta (definitions: object, registry: Registry, meta: Metadata): void {
|
||||
console.log('Writing packages/api/src/query.types.ts');
|
||||
|
||||
@@ -147,6 +152,7 @@ function generateForMeta (definitions: object, registry: Registry, meta: Metadat
|
||||
}
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export default function generateQuery (): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { TypeRegistry } from '../../codec/create';
|
||||
import { createImportCode, createImports, FOOTER, getSimilarTypes, HEADER, setImports } from '../util';
|
||||
|
||||
// Generate `packages/rpc-core/jsonrpc.types.ts`
|
||||
/** @internal */
|
||||
export default function generateRpcTypes (): void {
|
||||
console.log('Writing packages/rpc-core/jsonrpc.types.ts');
|
||||
|
||||
|
||||
@@ -17,17 +17,20 @@ interface Imports extends TypeImports {
|
||||
}
|
||||
|
||||
// helper to generate a `readonly <Name>: <Type>;` getter
|
||||
/** @internal */
|
||||
export function createGetter (definitions: object, name = '', type: string, imports: TypeImports, doc?: string): string {
|
||||
setImports(definitions, imports, [type]);
|
||||
|
||||
return ` /** ${doc || type} */\n readonly ${name}: ${type};\n`;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function errorUnhandled (definitions: object, def: TypeDef, imports: TypeImports): string {
|
||||
throw new Error(`Generate: ${name}: Unhandled type ${TypeDefInfo[def.info]}`);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsExport (definitions: object, def: TypeDef, imports: TypeImports): string {
|
||||
return exportInterface(def.name, formatType(definitions, def, imports));
|
||||
}
|
||||
@@ -39,6 +42,7 @@ const tsOption = tsExport;
|
||||
const tsPlain = tsExport;
|
||||
const tsTuple = tsExport;
|
||||
|
||||
/** @internal */
|
||||
function tsEnum (definitions: object, { name: enumName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Enum']);
|
||||
|
||||
@@ -62,6 +66,7 @@ function tsEnum (definitions: object, { name: enumName, sub }: TypeDef, imports:
|
||||
return exportInterface(enumName, 'Enum', keys.join(''));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsResultGetter (definitions: object, resultName = '', getter: 'Ok' | 'Error', def: TypeDef, imports: TypeImports): string {
|
||||
const { info, name = '', type } = def;
|
||||
const [resultType, asGetter] = type === 'Null'
|
||||
@@ -80,6 +85,7 @@ function tsResultGetter (definitions: object, resultName = '', getter: 'Ok' | 'E
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsResult (definitions: object, def: TypeDef, imports: TypeImports): string {
|
||||
const [okDef, errorDef] = (def.sub as TypeDef[]);
|
||||
const inner = [
|
||||
@@ -92,6 +98,7 @@ function tsResult (definitions: object, def: TypeDef, imports: TypeImports): str
|
||||
return exportInterface(def.name, formatType(definitions, def, imports), inner);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsSet (definitions: object, { name: setName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Set']);
|
||||
|
||||
@@ -102,6 +109,7 @@ function tsSet (definitions: object, { name: setName, sub }: TypeDef, imports: T
|
||||
return exportInterface(setName, 'Set', types.join(''));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsStruct (definitions: object, { name: structName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Struct']);
|
||||
|
||||
@@ -114,6 +122,7 @@ function tsStruct (definitions: object, { name: structName, sub }: TypeDef, impo
|
||||
return exportInterface(structName, 'Struct', keys.join(''));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsVec (definitions: object, def: TypeDef, imports: TypeImports): string {
|
||||
const type = def.info === TypeDefInfo.VecFixed
|
||||
? (def.ext as TypeDefExtVecFixed).type
|
||||
@@ -130,6 +139,7 @@ function tsVec (definitions: object, def: TypeDef, imports: TypeImports): string
|
||||
return exportInterface(def.name, formatType(definitions, def, imports));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function generateInterfaces (definitions: object, { types }: { types: Record<string, any> }, imports: Imports): [string, string][] {
|
||||
// handlers are defined externally to use - this means that when we do a
|
||||
// `generators[typedef.info](...)` TS will show any unhandled types. Rather
|
||||
@@ -158,6 +168,7 @@ function generateInterfaces (definitions: object, { types }: { types: Record<str
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function generateTsDefFor (importDefinitions: { [importPath: string]: object }, defName: string, { types }: { types: Record<string, any> }, outputDir: string): void {
|
||||
const imports = { ...createImports(importDefinitions, { types }), interfaces: [] } as Imports;
|
||||
const definitions = imports.definitions;
|
||||
@@ -195,6 +206,7 @@ function generateTsDefFor (importDefinitions: { [importPath: string]: object },
|
||||
fs.writeFileSync(path.join(outputDir, defName, 'index.ts'), HEADER.concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' });
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function generateTsDef (importDefinitions: { [importPath: string]: object }, outputDir: string, generatingPackage: string): void {
|
||||
const definitions = importDefinitions[generatingPackage];
|
||||
Object.entries(definitions).forEach(([defName, obj]): void => {
|
||||
@@ -209,6 +221,7 @@ export function generateTsDef (importDefinitions: { [importPath: string]: object
|
||||
fs.writeFileSync(path.join(outputDir, 'index.ts'), HEADER.concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' });
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export default function generateTsDefDefault (): void {
|
||||
generateTsDef(
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ import generateQueryTypes from './generateTypes/query';
|
||||
import generateRpcTypes from './generateTypes/rpc';
|
||||
import generateTsDef from './generateTypes/tsDef';
|
||||
|
||||
/** @internal */
|
||||
function main (): void {
|
||||
generateConstsTypes();
|
||||
generateInterfaceRegistry();
|
||||
|
||||
@@ -8,12 +8,14 @@ import UInt from '../../codec/UInt';
|
||||
|
||||
// See if a class is child of another class
|
||||
// FIMXE This could go in util some day
|
||||
/** @internal */
|
||||
export function isChildClass (Parent: Constructor<any>, Child: Constructor<any>): boolean {
|
||||
// https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
return Parent === Child || Parent.isPrototypeOf(Child);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isCompactEncodable (Child: Constructor<any>): boolean {
|
||||
return isChildClass(UInt, Child);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { setImports, TypeImports } from './imports';
|
||||
import * as primitiveClasses from '../../primitive';
|
||||
|
||||
// From `T`, generate `Compact<T>, Option<T>, Vec<T>`
|
||||
/** @internal */
|
||||
export function getDerivedTypes (definitions: object, type: string, primitiveName: string, imports: TypeImports): string[] {
|
||||
// `primitiveName` represents the actual primitive type our type is mapped to
|
||||
const isCompact = isCompactEncodable((primitiveClasses as any)[primitiveName]);
|
||||
@@ -50,6 +51,7 @@ export function getDerivedTypes (definitions: object, type: string, primitiveNam
|
||||
// Make types a little bit more flexible
|
||||
// - if param instanceof AbstractInt, then param: u64 | Uint8array | string | number
|
||||
// etc
|
||||
/** @internal */
|
||||
export function getSimilarTypes (definitions: object, registry: Registry, type: string, imports: TypeImports): string[] {
|
||||
const possibleTypes = [type];
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export const HEADER = '// Auto-generated via `yarn build:interfaces`, do not edi
|
||||
export const FOOTER = '\n';
|
||||
|
||||
// creates the import lines
|
||||
/** @internal */
|
||||
export function createImportCode (header: string, checks: { file: string; types: string[] }[]): string {
|
||||
return checks.reduce((result, { file, types }): string => {
|
||||
if (types.length) {
|
||||
@@ -23,6 +24,7 @@ export function createImportCode (header: string, checks: { file: string; types:
|
||||
}
|
||||
|
||||
// helper to generate a `export interface <Name> extends <Base> {<Body>}
|
||||
/** @internal */
|
||||
export function exportInterface (name = '', base: string, body = ''): string {
|
||||
return `/** ${base} */\nexport interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`;
|
||||
}
|
||||
@@ -30,6 +32,7 @@ export function exportInterface (name = '', base: string, body = ''): string {
|
||||
// helper to create an `export type <Name> = <Base>`
|
||||
// but since we don't want type alias (TS doesn't preserve names) we use
|
||||
// interface here.
|
||||
/** @internal */
|
||||
export function exportType (name = '', base: string): string {
|
||||
return exportInterface(name, base);
|
||||
}
|
||||
@@ -37,6 +40,7 @@ export function exportType (name = '', base: string): string {
|
||||
/**
|
||||
* Given the inner `K` & `V`, return a `BTreeMap<K, V>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatBTreeMap (key: string, val: string): string {
|
||||
return `BTreeMap<${key}, ${val}>`;
|
||||
}
|
||||
@@ -44,6 +48,7 @@ function formatBTreeMap (key: string, val: string): string {
|
||||
/**
|
||||
* Given the inner `V`, return a `BTreeSet<V>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatBTreeSet (val: string): string {
|
||||
return `BTreeSet<${val}>`;
|
||||
}
|
||||
@@ -51,6 +56,7 @@ function formatBTreeSet (val: string): string {
|
||||
/**
|
||||
* Given the inner `T`, return a `Compact<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatCompact (inner: string): string {
|
||||
return paramsNotation('Compact', inner);
|
||||
}
|
||||
@@ -58,6 +64,7 @@ function formatCompact (inner: string): string {
|
||||
/**
|
||||
* Given the inner `O` & `E`, return a `Result<O, E>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatResult (innerOk: string, innerError: string): string {
|
||||
return `Result<${innerOk}, ${innerError}>`;
|
||||
}
|
||||
@@ -65,6 +72,7 @@ function formatResult (innerOk: string, innerError: string): string {
|
||||
/**
|
||||
* Given the inner `T`, return a `Option<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatOption (inner: string): string {
|
||||
return paramsNotation('Option', inner);
|
||||
}
|
||||
@@ -72,6 +80,7 @@ function formatOption (inner: string): string {
|
||||
/**
|
||||
* Given the inners `T[]`, return a `ITuple<...T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatTuple (inners: string[]): string {
|
||||
return paramsNotation('ITuple', `[${inners.join(', ')}]`);
|
||||
}
|
||||
@@ -79,6 +88,7 @@ function formatTuple (inners: string[]): string {
|
||||
/**
|
||||
* Given the inner `T`, return a `Vec<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatVec (inner: string): string {
|
||||
return paramsNotation('Vec', inner);
|
||||
}
|
||||
@@ -86,6 +96,7 @@ function formatVec (inner: string): string {
|
||||
/**
|
||||
* Correctly format a given type
|
||||
*/
|
||||
/** @internal */
|
||||
export function formatType (definitions: object, type: string | TypeDef, imports: TypeImports): string {
|
||||
let typeDef: TypeDef;
|
||||
if (typeof type === 'string') {
|
||||
@@ -155,6 +166,7 @@ export function formatType (definitions: object, type: string | TypeDef, imports
|
||||
/**
|
||||
* Indent a string with `n` spaces before.
|
||||
*/
|
||||
/** @internal */
|
||||
export function indent (n: number, char = ' '): (str: string) => string {
|
||||
return function (str: string): string {
|
||||
return `${char.repeat(n)}${str}`;
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface TypeImports {
|
||||
|
||||
// Maps the types as found to the source location. This is used to generate the
|
||||
// imports in the output file, dep-duped and sorted
|
||||
/** @internal */
|
||||
export function setImports (definitions: object, imports: TypeImports, types: string[]): void {
|
||||
const { codecTypes, localTypes, ignoredTypes, primitiveTypes, typesTypes } = imports;
|
||||
|
||||
@@ -67,6 +68,7 @@ export function setImports (definitions: object, imports: TypeImports, types: st
|
||||
}
|
||||
|
||||
// Create an Imports object, can be prefilled with `ignoredTypes`
|
||||
/** @internal */
|
||||
export function createImports (importDefinitions: { [importPath: string]: object }, { types }: { types: Record<string, any> } = { types: {} }): TypeImports {
|
||||
const definitions = {} as Record<string, object>;
|
||||
const typeToModule = {} as Record<string, string>;
|
||||
|
||||
@@ -4688,7 +4688,7 @@ debug@3.1.0, debug@~3.1.0:
|
||||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6:
|
||||
debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5:
|
||||
version "3.2.6"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
|
||||
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
|
||||
@@ -4874,11 +4874,6 @@ detect-indent@^5.0.0:
|
||||
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
|
||||
integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50=
|
||||
|
||||
detect-libc@^1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
|
||||
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=
|
||||
|
||||
detect-newline@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
|
||||
@@ -6840,7 +6835,7 @@ humanize-url@^1.0.0:
|
||||
normalize-url "^1.0.0"
|
||||
strip-url-auth "^1.0.0"
|
||||
|
||||
iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
|
||||
iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
|
||||
version "0.4.24"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
|
||||
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
|
||||
@@ -9065,15 +9060,6 @@ natural-compare@^1.4.0:
|
||||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||
|
||||
needle@^2.2.1:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c"
|
||||
integrity sha512-4Hnwzr3mi5L97hMYeNl8wRW/Onhy4nUKR/lVemJ8gJedxxUyBLm9kkrDColJvoSfwi0jCNhD+xCdOtiGDQiRZg==
|
||||
dependencies:
|
||||
debug "^3.2.6"
|
||||
iconv-lite "^0.4.4"
|
||||
sax "^1.2.4"
|
||||
|
||||
negotiator@0.6.2:
|
||||
version "0.6.2"
|
||||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
|
||||
@@ -9206,22 +9192,6 @@ node-notifier@^6.0.0:
|
||||
shellwords "^0.1.1"
|
||||
which "^1.3.1"
|
||||
|
||||
node-pre-gyp@*:
|
||||
version "0.14.0"
|
||||
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83"
|
||||
integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA==
|
||||
dependencies:
|
||||
detect-libc "^1.0.2"
|
||||
mkdirp "^0.5.1"
|
||||
needle "^2.2.1"
|
||||
nopt "^4.0.1"
|
||||
npm-packlist "^1.1.6"
|
||||
npmlog "^4.0.2"
|
||||
rc "^1.2.7"
|
||||
rimraf "^2.6.1"
|
||||
semver "^5.3.0"
|
||||
tar "^4.4.2"
|
||||
|
||||
node-releases@^1.1.46:
|
||||
version "1.1.47"
|
||||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.47.tgz#c59ef739a1fd7ecbd9f0b7cf5b7871e8a8b591e4"
|
||||
@@ -9338,7 +9308,7 @@ npm-normalize-package-bin@^1.0.0, npm-normalize-package-bin@^1.0.1:
|
||||
semver "^5.6.0"
|
||||
validate-npm-package-name "^3.0.0"
|
||||
|
||||
npm-packlist@^1.1.6, npm-packlist@^1.4.4:
|
||||
npm-packlist@^1.4.4:
|
||||
version "1.4.8"
|
||||
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.8.tgz#56ee6cc135b9f98ad3d51c1c95da22bbb9b2ef3e"
|
||||
integrity sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==
|
||||
@@ -9370,7 +9340,7 @@ npm-run-path@^4.0.0:
|
||||
dependencies:
|
||||
path-key "^3.0.0"
|
||||
|
||||
npmlog@^4.0.2, npmlog@^4.1.2:
|
||||
npmlog@^4.1.2:
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
|
||||
integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==
|
||||
@@ -11225,7 +11195,7 @@ rimraf@2.6.3:
|
||||
dependencies:
|
||||
glob "^7.1.3"
|
||||
|
||||
rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3:
|
||||
rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3:
|
||||
version "2.7.1"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
|
||||
integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==
|
||||
@@ -11317,7 +11287,7 @@ sass-lookup@^3.0.0:
|
||||
dependencies:
|
||||
commander "^2.16.0"
|
||||
|
||||
sax@^1.2.4, sax@~1.2.4:
|
||||
sax@~1.2.4:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
|
||||
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
|
||||
@@ -12196,7 +12166,7 @@ tapable@^1.0.0, tapable@^1.1.3:
|
||||
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2"
|
||||
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==
|
||||
|
||||
tar@^4.4.10, tar@^4.4.12, tar@^4.4.2, tar@^4.4.8:
|
||||
tar@^4.4.10, tar@^4.4.12, tar@^4.4.8:
|
||||
version "4.4.13"
|
||||
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525"
|
||||
integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==
|
||||
|
||||
Reference in New Issue
Block a user