More small readability enhancements (#1296)

* More small readability enhancements

* Pacify CC on manual checks
This commit is contained in:
Jaco Greeff
2019-08-11 22:44:02 +02:00
committed by GitHub
parent a12a776392
commit 5ee2caf00e
8 changed files with 91 additions and 87 deletions
@@ -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)
+1 -5
View File
@@ -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++) {