More small readability enhancements (#1296)
* More small readability enhancements * Pacify CC on manual checks
This commit is contained in:
@@ -8,34 +8,34 @@ import { getTypeDef } from '../../codec/createType';
|
||||
import flattenUniq from './flattenUniq';
|
||||
import { getTypeRegistry } from '../../codec';
|
||||
|
||||
function extractTypes (types: string[]): any[] {
|
||||
return types.map((type): any => {
|
||||
const decoded = getTypeDef(type);
|
||||
|
||||
switch (decoded.info) {
|
||||
case TypeDefInfo.Plain:
|
||||
return decoded.type;
|
||||
|
||||
case TypeDefInfo.Compact:
|
||||
case TypeDefInfo.Option:
|
||||
case TypeDefInfo.Vec:
|
||||
return extractTypes([(decoded.sub as TypeDef).type]);
|
||||
|
||||
case TypeDefInfo.VecFixed:
|
||||
return extractTypes([(decoded.ext as TypeDefExtVecFixed).type]);
|
||||
|
||||
case TypeDefInfo.Tuple:
|
||||
return extractTypes(
|
||||
(decoded.sub as TypeDef[]).map((sub): string => sub.type)
|
||||
);
|
||||
|
||||
default:
|
||||
throw new Error(`Uhandled: Unnable to create and validate type from ${type}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default function validateTypes (types: string[], throwError: boolean): void {
|
||||
const extractTypes = (types: string[]): any[] => {
|
||||
return types.map((type): any => {
|
||||
const decoded = getTypeDef(type);
|
||||
|
||||
switch (decoded.info) {
|
||||
case TypeDefInfo.Plain:
|
||||
return decoded.type;
|
||||
|
||||
case TypeDefInfo.Compact:
|
||||
case TypeDefInfo.Option:
|
||||
case TypeDefInfo.Vec:
|
||||
return extractTypes([(decoded.sub as TypeDef).type]);
|
||||
|
||||
case TypeDefInfo.VecFixed:
|
||||
return extractTypes([(decoded.ext as TypeDefExtVecFixed).type]);
|
||||
|
||||
case TypeDefInfo.Tuple:
|
||||
return extractTypes(
|
||||
(decoded.sub as TypeDef[]).map((sub): string => sub.type)
|
||||
);
|
||||
|
||||
default:
|
||||
throw new Error(`Uhandled: Unnable to create and validate type from ${type}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const typeRegistry = getTypeRegistry();
|
||||
const missing = flattenUniq(extractTypes(types)).filter((type): boolean =>
|
||||
!typeRegistry.hasType(type)
|
||||
|
||||
@@ -25,11 +25,7 @@ type FromReg<T extends Codec, K extends string> = K extends InterfaceTypes ? Int
|
||||
|
||||
// safely split a string on ', ' while taking care of any nested occurences
|
||||
export function typeSplit (type: string): string[] {
|
||||
let cDepth = 0; // compact/doublemap/linkedmap/option/vector depth
|
||||
let fDepth = 0; // vector (fixed) depth
|
||||
let sDepth = 0; // struct depth
|
||||
let tDepth = 0; // tuple depth
|
||||
let start = 0;
|
||||
let [cDepth, fDepth, sDepth, tDepth, start] = [0, 0, 0, 0, 0];
|
||||
const result = [];
|
||||
|
||||
for (let index = 0; index < type.length; index++) {
|
||||
|
||||
Reference in New Issue
Block a user