From 5a929d3810ac39e79504e9709dcb1fdc9612bc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerem=C3=ADas=20D=C3=ADaz?= Date: Fri, 24 Apr 2020 09:28:47 -0400 Subject: [PATCH] remove unnecessary parentheses and duplicate types (#2204) * remove unnecessary parentheses and duplicate types * fix: remove test code --- packages/api/src/augment/rpc.ts | 4 ++-- packages/api/src/augment/tx.ts | 10 +++++----- packages/typegen/src/generate/interfaceRegistry.ts | 9 ++++++++- packages/typegen/src/util/derived.ts | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index a3b80d3738..881a203911 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -144,11 +144,11 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { /** * Get offchain local storage under given key and prefix **/ - localStorageGet: AugmentedRpc<(kind: StorageKind | ('__UNUSED' | 'PERSISTENT' | 'LOCAL') | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable>>; + localStorageGet: AugmentedRpc<(kind: StorageKind | '__UNUSED' | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable>>; /** * Set offchain local storage under given key and prefix **/ - localStorageSet: AugmentedRpc<(kind: StorageKind | ('__UNUSED' | 'PERSISTENT' | 'LOCAL') | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable>; + localStorageSet: AugmentedRpc<(kind: StorageKind | '__UNUSED' | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable>; }; payment: { /** diff --git a/packages/api/src/augment/tx.ts b/packages/api/src/augment/tx.ts index 356e28fa5f..4ad7e2af95 100644 --- a/packages/api/src/augment/tx.ts +++ b/packages/api/src/augment/tx.ts @@ -237,7 +237,7 @@ declare module '@polkadot/api/types/submittable' { * # * # **/ - delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | 'None'|'Locked1x'|'Locked2x'|'Locked3x'|'Locked4x'|'Locked5x'|'Locked6x' | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic>; /** * Schedule an emergency cancellation of a referendum. Cannot happen twice to the same * referendum. @@ -375,7 +375,7 @@ declare module '@polkadot/api/types/submittable' { * # * # **/ - proxyDelegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic>; + proxyDelegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | 'None'|'Locked1x'|'Locked2x'|'Locked3x'|'Locked4x'|'Locked5x'|'Locked6x' | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic>; /** * Remove a proxied vote for a referendum. * Exactly equivalent to `remove_vote` except that it operates on the account that the @@ -1144,7 +1144,7 @@ declare module '@polkadot/api/types/submittable' { * Total Complexity: O(M + logM + B + X) * # **/ - judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | ('Rebid' | 'Reject' | 'Approve') | number | Uint8Array) => SubmittableExtrinsic>; + judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | 'Rebid'|'Reject'|'Approve' | number | Uint8Array) => SubmittableExtrinsic>; /** * Allow suspension judgement origin to make judgement on a suspended member. * If a suspended member is forgiven, we simply add them back as a member, not affecting @@ -1322,7 +1322,7 @@ declare module '@polkadot/api/types/submittable' { * unless the `origin` falls below _existential deposit_ and gets removed as dust. * # **/ - bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array, payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic>; + bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact | AnyNumber | Uint8Array, payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic>; /** * Add some extra amount that have appeared in the stash `free_balance` into the balance up * for staking. @@ -1506,7 +1506,7 @@ declare module '@polkadot/api/types/submittable' { * - Writes are limited to the `origin` account key. * # **/ - setPayee: AugmentedSubmittable<(payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic>; + setPayee: AugmentedSubmittable<(payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic>; /** * The ideal number of validators. **/ diff --git a/packages/typegen/src/generate/interfaceRegistry.ts b/packages/typegen/src/generate/interfaceRegistry.ts index 6e0fc1259c..5383fa18b1 100644 --- a/packages/typegen/src/generate/interfaceRegistry.ts +++ b/packages/typegen/src/generate/interfaceRegistry.ts @@ -20,6 +20,7 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string const imports = createImports(importDefinitions); const definitions = imports.definitions; + const primitives = Object .keys(primitiveClasses) .filter((name): boolean => !!name.indexOf('Generic')) @@ -32,13 +33,19 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string ].join('\n'); }, ''); + const existingTypes: Record = {}; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const srml = Object.entries(definitions).reduce((accumulator, [_defName, { types }]): string => { setImports(definitions, imports, Object.keys(types)); + const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]); + + uniqueTypes.forEach((type) => { existingTypes[type] = true; }); + return [ accumulator, - ...Object.keys(types).map((type): string => + ...uniqueTypes.map((type): string => getDerivedTypes(definitions, type, types[type], imports).map(indent(4)).join('\n') ) ].join('\n'); diff --git a/packages/typegen/src/util/derived.ts b/packages/typegen/src/util/derived.ts index 73599c0483..11655b97f2 100644 --- a/packages/typegen/src/util/derived.ts +++ b/packages/typegen/src/util/derived.ts @@ -27,7 +27,7 @@ import { formatType } from './formatting'; import { setImports, TypeImports } from './imports'; function arrayToStrType (arr: string[]): string { - return `(${arr.map((c): string => `'${c}'`).join(' | ')})`; + return `${arr.map((c): string => `'${c}'`).join(' | ')}`; } const voteConvictions = arrayToStrType(AllConvictions);