Introduce bundle exports (#3742)

* Introduce bundle exports

* Move memo

* Cleanup imports

* Move DoNotConstruct
This commit is contained in:
Jaco
2021-07-07 11:35:30 +02:00
committed by GitHub
parent 33ee38dc7a
commit 81be70e15b
41 changed files with 874 additions and 792 deletions
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './codec';
export * from './create';
export * from './index.types';
export { packageInfo } from './packageInfo';
export { TypeDefInfo } from './types';
-6
View File
@@ -1,6 +0,0 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import * as Classes from './index.types';
export type CodecTypes = keyof typeof Classes;
@@ -0,0 +1,82 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecHash, Hash } from '../interfaces/runtime';
import type { AnyJson, Codec, Constructor, Registry } from '../types';
/**
* @name DoNotConstruct
* @description
* An unknown type that fails on construction with the type info
*/
export class DoNotConstruct implements Codec {
public readonly registry: Registry;
public createdAtHash?: Hash;
#neverError: Error;
constructor (registry: Registry, typeName = 'DoNotConstruct') {
this.registry = registry;
this.#neverError = new Error(`Cannot construct unknown type ${typeName}`);
throw this.#neverError;
}
public static with (typeName?: string): Constructor {
return class extends DoNotConstruct {
constructor (registry: Registry) {
super(registry, typeName);
}
};
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
throw this.#neverError;
}
/**
* @description returns a hash of the contents
*/
public get hash (): CodecHash {
throw this.#neverError;
}
/**
* @description Checks if the value is an empty value (always true)
*/
public get isEmpty (): boolean {
throw this.#neverError;
}
eq (): boolean {
throw this.#neverError;
}
toHex (): string {
throw this.#neverError;
}
toHuman (): AnyJson {
throw this.#neverError;
}
toJSON (): AnyJson {
throw this.#neverError;
}
toRawType (): string {
throw this.#neverError;
}
toString (): string {
throw this.#neverError;
}
toU8a (): Uint8Array {
throw this.#neverError;
}
}
+1
View File
@@ -11,6 +11,7 @@ export { BTreeMap } from './BTreeMap';
export { BTreeSet } from './BTreeSet';
export { Compact } from './Compact';
// export { CodecDate, CodecDate as Date } from './Date';
export { DoNotConstruct } from './DoNotConstruct';
export { Enum } from './Enum';
export { HashMap } from './HashMap';
export { Int } from './Int';
+1 -2
View File
@@ -7,8 +7,7 @@ import type { FromReg, TypeDef } from './types';
import { assert, isNumber, isUndefined, stringify } from '@polkadot/util';
import { BTreeMap, BTreeSet, CodecSet, Compact, Enum, HashMap, Int, Option, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed } from '../codec';
import { DoNotConstruct } from '../primitive';
import { BTreeMap, BTreeSet, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Option, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed } from '../codec';
import { getTypeDef } from './getTypeDef';
import { TypeDefInfo } from './types';
+2 -2
View File
@@ -8,8 +8,8 @@ import type { Codec, Constructor } from '../types';
import { isChildClass, u8aToU8a } from '@polkadot/util';
import { keccakAsU8a } from '@polkadot/util-crypto';
import { Struct } from '../codec';
import { DoNotConstruct, Text, U32 } from '../primitive';
import { DoNotConstruct, Struct } from '../codec';
import { Text, U32 } from '../primitive';
import { TypeRegistry } from '.';
describe('TypeRegistry', (): void => {
+1 -1
View File
@@ -13,13 +13,13 @@ import { Metadata } from '@polkadot/metadata/Metadata';
import { assert, assertReturn, BN_ZERO, formatBalance, isFunction, isString, isU8a, logger, stringCamelCase, stringify, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { DoNotConstruct } from '../codec/DoNotConstruct';
import { Json } from '../codec/Json';
import { Raw } from '../codec/Raw';
import { expandExtensionTypes, fallbackExtensions, findUnknownExtensions } from '../extrinsic/signedExtensions';
import { GenericEventData } from '../generic/Event';
import * as baseTypes from '../index.types';
import * as definitions from '../interfaces/definitions';
import { DoNotConstruct } from '../primitive/DoNotConstruct';
import { createClass, getTypeClass } from './createClass';
import { createType } from './createType';
import { getTypeDef } from './getTypeDef';
+1 -4
View File
@@ -3,7 +3,4 @@
import './detectPackage';
export * from './codec';
export * from './create';
export * from './index.types';
export { packageInfo } from './packageInfo';
export * from './bundle';
@@ -1,27 +0,0 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Constructor, Registry } from '../types';
import { Null } from './Null';
/**
* @name DoNotConstruct
* @description
* An unknown type that fails on construction with the type info
*/
export class DoNotConstruct extends Null {
constructor (registry: Registry, typeName = 'DoNotConstruct') {
super(registry);
throw new Error(`Cannot construct unknown type ${typeName}`);
}
public static with (typeName?: string): Constructor {
return class extends DoNotConstruct {
constructor (registry: Registry) {
super(registry, typeName);
}
};
}
}
+1 -1
View File
@@ -2,12 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
import type { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata';
import type { AllHashers } from '../interfaces/metadata/definitions';
import type { AnyJson, AnyTuple, AnyU8a, Codec, InterfaceTypes, IStorageKey, Registry } from '../types';
import type { StorageEntry } from './types';
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
import { AllHashers } from '../interfaces/metadata/definitions';
import { Bytes } from './Bytes';
interface Decoded {
-1
View File
@@ -8,7 +8,6 @@ export { BitVec } from './BitVec';
export { bool, bool as Bool } from './Bool';
export { Bytes } from './Bytes';
export { Data } from './Data';
export { DoNotConstruct } from './DoNotConstruct';
export { i8, i8 as I8 } from './I8';
export { i16, i16 as I16 } from './I16';
export { i32, i32 as I32 } from './I32';