Extract full interfaceRegistry (#1927)
* Extract full interfaceRegistry * Move augment to top-level in api & types * Type augment output * Update with new augmented paths * Update RPC path
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// Module augmentation so that `api.{consts,query,rpc,tx}.*.*` work
|
||||
import '@polkadot/api/types/augment';
|
||||
import '@polkadot/api/augment';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
|
||||
|
||||
@@ -21,7 +21,7 @@ function generate (metaHex: string, pkg: string | undefined, output: string, isS
|
||||
const extraTypes = pkg
|
||||
? { [pkg]: require(path.join(process.cwd(), output, 'definitions')) }
|
||||
: {};
|
||||
const hasRegistry = fs.existsSync(path.join(process.cwd(), output, 'augment-registry.ts'));
|
||||
const hasRegistry = fs.existsSync(path.join(process.cwd(), output, 'augment-types.ts'));
|
||||
|
||||
generateConst(path.join(process.cwd(), output, 'augment-consts.ts'), metaHex, extraTypes, isStrict);
|
||||
generateQuery(path.join(process.cwd(), output, 'augment-query.ts'), metaHex, extraTypes, isStrict);
|
||||
@@ -31,8 +31,8 @@ function generate (metaHex: string, pkg: string | undefined, output: string, isS
|
||||
[
|
||||
HEADER,
|
||||
...[
|
||||
'@polkadot/api/types/augment/rpc',
|
||||
...['consts', 'query', hasRegistry ? 'registry' : '', 'tx'].filter((key) => !!key).map((key) => `./augment-${key}`)
|
||||
'@polkadot/api/augment/rpc',
|
||||
...['consts', 'query', hasRegistry ? 'types' : '', 'tx'].filter((key) => !!key).map((key) => `./augment-${key}`)
|
||||
].map((path) => `import '${path}';\n`)
|
||||
].join('')
|
||||
);
|
||||
|
||||
@@ -49,5 +49,5 @@ export default function main (): void {
|
||||
};
|
||||
|
||||
generateTsDef(allDefs, path.join(process.cwd(), input), pkg);
|
||||
generateInterfaceRegistry({ [pkg]: userDefs }, path.join(process.cwd(), input, 'augment-registry.ts'), true);
|
||||
generateInterfaceRegistry({ [pkg]: userDefs }, path.join(process.cwd(), input, 'augment-types.ts'));
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<strin
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export default function generateConsts (dest = 'packages/api/src/types/augment/consts.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
export default function generateConsts (dest = 'packages/api/src/augment/consts.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registerDefinitions(registry, extraTypes);
|
||||
|
||||
@@ -14,13 +14,13 @@ const primitiveClasses = {
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export function generateInterfaceRegistry (importDefinitions: { [importPath: string]: object }, dest: string, skipPrimitives?: boolean): void {
|
||||
export function generateInterfaceRegistry (importDefinitions: { [importPath: string]: object }, dest: string): void {
|
||||
writeFile(dest, (): string => {
|
||||
Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {} as object);
|
||||
|
||||
const imports = createImports(importDefinitions);
|
||||
const definitions = imports.definitions;
|
||||
const primitives = skipPrimitives ? '' : Object
|
||||
const primitives = Object
|
||||
.keys(primitiveClasses)
|
||||
.filter((name): boolean => !!name.indexOf('Generic'))
|
||||
.reduce((accumulator, primitiveName): string => {
|
||||
@@ -67,6 +67,6 @@ export function generateInterfaceRegistry (importDefinitions: { [importPath: str
|
||||
export default function generateDefaultInterfaceRegistry (): void {
|
||||
generateInterfaceRegistry(
|
||||
{ '@polkadot/types/interfaces': defaultDefinitions },
|
||||
'packages/types/src/interfaceAugment.ts'
|
||||
'packages/types/src/augment/interfaceRegistry.ts'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export default function generateQuery (dest = 'packages/api/src/types/augment/query.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
export default function generateQuery (dest = 'packages/api/src/augment/query.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registerDefinitions(registry, extraTypes);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { FOOTER, HEADER, createDocComments, createImportCode, createImports, getSimilarTypes, setImports, writeFile, indent } from '../util';
|
||||
|
||||
/** @internal */
|
||||
export default function generateRpcTypes (dest = 'packages/api/src/types/augment/rpc.ts'): void {
|
||||
export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.ts'): void {
|
||||
writeFile(dest, (): string => {
|
||||
const registry = new TypeRegistry();
|
||||
const imports = createImports({ '@polkadot/types/interfaces': definitions });
|
||||
|
||||
@@ -100,7 +100,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export default function generateTx (dest = 'packages/api/src/types/augment/tx.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
export default function generateTx (dest = 'packages/api/src/augment/tx.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registerDefinitions(registry, extraTypes);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2020 @polkadot/api 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 './interfaceRegistry';
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// augment the registry
|
||||
import '@polkadot/types/interfaceAugment';
|
||||
import '@polkadot/types/augment';
|
||||
import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
Reference in New Issue
Block a user