Add codec exports to types index (#689)

* Add codec exports to types index

* Use actual index exports (internally)

* Merge {AccountId, Balance, Moment}Of into parent classes
This commit is contained in:
Jaco Greeff
2019-02-13 16:00:59 +01:00
committed by GitHub
parent 271529766d
commit f95763906e
21 changed files with 136 additions and 159 deletions
+8
View File
@@ -61,3 +61,11 @@ export default class AccountId extends U8aFixed {
return AccountId.encode(this);
}
}
/**
* @name AccountIdOf
* @description
* The Substrate AccountIdOf representation as a [[AccountId]].
*/
export class AccountIdOf extends AccountId {
}
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 AccountId from './AccountId';
/**
* @name AccountIdOf
* @description
* The Substrate AccountIdOf representation as a [[AccountId]].
*/
export default class AccountIdOf extends AccountId {
}
+8
View File
@@ -11,3 +11,11 @@ import U128 from './U128';
*/
export default class Balance extends U128 {
}
/**
* @name BalanceOf
* @description
* The Substrate BalanceOf representation as a [[Balance]].
*/
export class BalanceOf extends Balance {
}
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 Balance from './Balance';
/**
* @name BalanceOf
* @description
* The Substrate BalanceOf representation as a [[Balance]].
*/
export default class BalanceOf extends Balance {
}
+8
View File
@@ -110,3 +110,11 @@ export default class Moment extends Date implements Codec {
return bnToU8a(this.toNumber(), BITLENGTH, true);
}
}
/**
* @name MomentOf
* @description
* The Substrate MomentOf representation as a [[Moment]].
*/
export class MomentOf extends Moment {
}
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 Moment from './Moment';
/**
* @name MomentOf
* @description
* The Substrate MomentOf representation as a [[Moment]].
*/
export default class MomentOf extends Moment {
}
+1 -1
View File
@@ -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.
import { createType } from '@polkadot/types/codec';
import { createType } from '@polkadot/types/index';
import json from './json/StorageChangeSet.001.json';
import StorageChangeSet from './StorageChangeSet';
+1 -1
View File
@@ -184,7 +184,7 @@ export function getTypeClass (value: TypeDef): Constructor {
}
// NOTE We only load types via require - we have to avoid circular deps between type usage and creation
const Types = require('../index');
const Types = require('../index.classes');
const Type = registry.get(value.type) || Types[value.type];
assert(Type, `Unable to determine type from '${value.type}'`);
+1
View File
@@ -23,3 +23,4 @@ export { default as UInt } from './UInt';
// Type management helper functions
export { default as createType, getTypeClass, getTypeDef, TypeDef, TypeDefInfo } from './createType';
export { default as typeRegistry } from './typeRegistry';
+95
View File
@@ -0,0 +1,95 @@
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// NOTE When adding any types here, we need to update the coumentation links as
// well - <root>/docs/SUMMARY.md as well as ../README.md
/**
* @summary Type definitions that are used in the system
*/
export { default as AccountId, AccountIdOf } from './AccountId';
export { default as AccountIndex } from './AccountIndex';
export { default as Address } from './Address';
export { default as AttestedCandidate } from './AttestedCandidate';
export { default as AuthorityId } from './AuthorityId';
export { default as Balance, BalanceOf } from './Balance';
// NOTE Bft items are only used in internal structures
// export * from './Bft;
export { default as Block } from './Block';
export { default as BlockNumber } from './BlockNumber';
// NOTE We are exporting Bool as bool to match with Rust
export { default as bool } from './Bool';
export { default as Bytes } from './Bytes';
export { default as ChainProperties } from './ChainProperties';
export { default as CodeHash } from './CodeHash';
export { default as Data } from './Data';
export { default as Digest } from './Digest';
export { default as Event } from './Event';
export { default as EventRecord } from './EventRecord';
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra } from './ExtrinsicEra';
export { default as ExtrinsicSignature } from './ExtrinsicSignature';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
// NOTE Only used internally, exported as PendingExtrinsics
// export { default as Extrinsics } from './Extrinsics';
export { default as Gas } from './Gas';
export { default as H256 } from './H256';
export { default as H512 } from './H512';
export { default as Hash } from './Hash';
export { default as Header } from './Header';
export { default as Health } from './Health';
export { default as i8 } from './I8';
export { default as i16 } from './I16';
export { default as i32 } from './I32';
export { default as i64 } from './I64';
export { default as i128 } from './I128';
export { default as i256 } from './I256';
export { default as InherentOfflineReport } from './InherentOfflineReport';
export { default as KeyValue } from './KeyValue';
export { default as LockPeriods } from './LockPeriods';
export { default as Metadata } from './Metadata';
export { default as Method } from './Method';
export { default as MisbehaviorReport } from './MisbehaviorReport';
export { default as Moment, MomentOf } from './Moment';
export { default as NewAccountOutcome } from './NewAccountOutcome';
export { default as Null } from './Null';
// NOTE Nonce is renamed to Index
export { default as Index } from './Nonce';
export { default as IndexCompact } from './NonceCompact';
export { default as Justification } from './Justification';
export { default as Origin } from './Origin';
export { default as ParaId } from './ParaId';
export { default as PeerInfo } from './PeerInfo';
export { default as PendingExtrinsics } from './PendingExtrinsics';
export { default as Permill } from './Permill';
export { default as Perbill } from './Perbill';
export { default as PropIndex } from './PropIndex';
export { default as Proposal } from './Proposal';
export { default as ProposalIndex } from './ProposalIndex';
export { default as ReferendumIndex } from './ReferendumIndex';
export { default as ReferendumInfo } from './ReferendumInfo';
export { default as RuntimeVersion } from './RuntimeVersion';
export { default as Schedule } from './Schedule';
export { default as SeedOf } from './SeedOf';
export { default as SessionKey } from './SessionKey';
export { default as Signature } from './Signature';
export { default as SignedBlock } from './SignedBlock';
export { default as StorageChangeSet } from './StorageChangeSet';
export { default as StorageData } from './StorageData';
export { default as StorageKey } from './StorageKey';
export { default as StoredPendingChange } from './StoredPendingChange';
export { default as Text } from './Text';
export { default as Type } from './Type';
// NOTE We are exporting the U* classes as lowercase, matching with Rust
export { default as u8 } from './U8';
export { default as u16 } from './U16';
export { default as u32 } from './U32';
export { default as u64 } from './U64';
export { default as u128 } from './U128';
export { default as u256 } from './U256';
export { default as usize } from './USize';
export { default as ValidatorPrefs } from './ValidatorPrefs';
export { default as Vote } from './Vote';
export { default as VoteThreshold } from './VoteThreshold';
export { default as VoteIndex } from './VoteIndex';
+2 -2
View File
@@ -6,9 +6,9 @@ import { Constructor } from './types';
import extrinsics from '@polkadot/extrinsics/static';
import * as _Types from './index';
import * as Classes from './index.classes';
const Types = _Types as { [index: string]: Constructor };
const Types = Classes as { [index: string]: Constructor };
describe('types', () => {
describe('default creation', () => {
+2 -96
View File
@@ -5,99 +5,5 @@
// NOTE When adding any types here, we need to update the coumentation links as
// well - <root>/docs/SUMMARY.md as well as ../README.md
// NOTE We are not re-exporting the index.ts from codec here. The reasoning being
// that these should be enough to actually _use_ the codec, i.e. from a api-user
// perspective these are the value classes. (Codec is for the cases where you need
// to construct values dynamically)
/**
* @summary Type definitions that are used in the system
*/
export { default as AccountId } from './AccountId';
export { default as AccountIdOf } from './AccountIdOf';
export { default as AccountIndex } from './AccountIndex';
export { default as Address } from './Address';
export { default as AttestedCandidate } from './AttestedCandidate';
export { default as AuthorityId } from './AuthorityId';
export { default as Balance } from './Balance';
export { default as BalanceOf } from './BalanceOf';
// NOTE Bft items are only used in internal structures
// export * from './Bft;
export { default as Block } from './Block';
export { default as BlockNumber } from './BlockNumber';
// NOTE We are exporting Bool as bool to match with Rust
export { default as bool } from './Bool';
export { default as Bytes } from './Bytes';
export { default as ChainProperties } from './ChainProperties';
export { default as CodeHash } from './CodeHash';
export { default as Data } from './Data';
export { default as Digest } from './Digest';
export { default as Event } from './Event';
export { default as EventRecord } from './EventRecord';
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra } from './ExtrinsicEra';
export { default as ExtrinsicSignature } from './ExtrinsicSignature';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
// NOTE Only used internally, exported as PendingExtrinsics
// export { default as Extrinsics } from './Extrinsics';
export { default as Gas } from './Gas';
export { default as H256 } from './H256';
export { default as H512 } from './H512';
export { default as Hash } from './Hash';
export { default as Header } from './Header';
export { default as Health } from './Health';
export { default as i8 } from './I8';
export { default as i16 } from './I16';
export { default as i32 } from './I32';
export { default as i64 } from './I64';
export { default as i128 } from './I128';
export { default as i256 } from './I256';
export { default as InherentOfflineReport } from './InherentOfflineReport';
export { default as KeyValue } from './KeyValue';
export { default as LockPeriods } from './LockPeriods';
export { default as Metadata } from './Metadata';
export { default as Method } from './Method';
export { default as MisbehaviorReport } from './MisbehaviorReport';
export { default as Moment } from './Moment';
export { default as MomentOf } from './MomentOf';
export { default as NewAccountOutcome } from './NewAccountOutcome';
export { default as Null } from './Null';
// NOTE Nonce is renamed to Index
export { default as Index } from './Nonce';
export { default as IndexCompact } from './NonceCompact';
export { default as Justification } from './Justification';
export { default as Origin } from './Origin';
export { default as ParaId } from './ParaId';
export { default as PeerInfo } from './PeerInfo';
export { default as PendingExtrinsics } from './PendingExtrinsics';
export { default as Permill } from './Permill';
export { default as Perbill } from './Perbill';
export { default as PropIndex } from './PropIndex';
export { default as Proposal } from './Proposal';
export { default as ProposalIndex } from './ProposalIndex';
export { default as ReferendumIndex } from './ReferendumIndex';
export { default as ReferendumInfo } from './ReferendumInfo';
export { default as RuntimeVersion } from './RuntimeVersion';
export { default as Schedule } from './Schedule';
export { default as SeedOf } from './SeedOf';
export { default as SessionKey } from './SessionKey';
export { default as Signature } from './Signature';
export { default as SignedBlock } from './SignedBlock';
export { default as StorageChangeSet } from './StorageChangeSet';
export { default as StorageData } from './StorageData';
export { default as StorageKey } from './StorageKey';
export { default as StoredPendingChange } from './StoredPendingChange';
export { default as Text } from './Text';
export { default as Type } from './Type';
// NOTE We are exporting the U* classes as lowercase, matching with Rust
export { default as u8 } from './U8';
export { default as u16 } from './U16';
export { default as u32 } from './U32';
export { default as u64 } from './U64';
export { default as u128 } from './U128';
export { default as u256 } from './U256';
export { default as usize } from './USize';
export { default as ValidatorPrefs } from './ValidatorPrefs';
export { default as Vote } from './Vote';
export { default as VoteThreshold } from './VoteThreshold';
export { default as VoteIndex } from './VoteIndex';
export * from './codec';
export * from './index.classes';