Add .keys on storage entries (#2032)

* Add .keys on storage entries

* Pass isOptional to storage type unwrap

* Linked maps TS types
This commit is contained in:
Jaco Greeff
2020-03-12 09:12:11 +01:00
committed by GitHub
parent fc477b98bd
commit c2f9ef7ca8
11 changed files with 82 additions and 73 deletions
+1
View File
@@ -14,6 +14,7 @@ export { default as Compact } from './Compact';
// export { default as Date } from './Date';
export { default as Enum } from './Enum';
export { default as HashMap } from './HashMap';
export { default as Linkage } from './Linkage';
export { default as Option } from './Option';
export { default as Result } from './Result';
export { default as Set } from './Set';
+12 -4
View File
@@ -43,9 +43,7 @@ const HASHER_MAP: Record<keyof typeof metadataDefs.types.StorageHasherV10._enum,
};
const HASHER_OPTS = Object.values(HASHER_MAP);
// we unwrap the type here, turning into an output usable for createType
/** @internal */
export function unwrapStorageType (type: StorageEntryTypeLatest): keyof InterfaceTypes {
function getStorageType (type: StorageEntryTypeLatest): string {
if (type.isPlain) {
return type.asPlain.toString() as keyof InterfaceTypes;
} else if (type.isDoubleMap) {
@@ -58,7 +56,17 @@ export function unwrapStorageType (type: StorageEntryTypeLatest): keyof Interfac
return `(${map.value.toString()}, Linkage<${map.key.toString()}>)` as keyof InterfaceTypes;
}
return map.value.toString() as keyof InterfaceTypes;
return map.value.toString();
}
// we unwrap the type here, turning into an output usable for createType
/** @internal */
export function unwrapStorageType (type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
const outputType = getStorageType(type);
return isOptional
? `Option<${outputType}>` as keyof InterfaceTypes
: outputType as keyof InterfaceTypes;
}
/** @internal */