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:
@@ -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';
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user