Expand bool & Enum generation (#1785)
* Expand bool & Enum generation * Swap consts to Augmented (align with others)
This commit is contained in:
@@ -27,7 +27,7 @@ function generateModule (allDefs: object, { constants, name }: ModuleMetadataLat
|
||||
setImports(allDefs, imports, [type.toString()]);
|
||||
|
||||
return createDocComments(documentation).map((d): string => indent(6)(d)).join('\n') +
|
||||
indent(6)(`${stringCamelCase(name.toString())}: ${type} & ConstantCodec;`);
|
||||
indent(6)(`${stringCamelCase(name.toString())}: AugmentedConst<${type}>;`);
|
||||
}))
|
||||
.concat([indent(4)('};')]);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ function generateModule (registry: Registry, allDefs: object, { calls, name }: M
|
||||
});
|
||||
|
||||
return createDocComments(documentation).map((d): string => indent(6)(d)).join('\n') +
|
||||
indent(6)(`${stringCamelCase(name.toString())}: AugmentedExtrinsic<(${params.map(([full]): string => full).join(', ')}) => SubmittableExtrinsic<ApiType>>;`);
|
||||
indent(6)(`${stringCamelCase(name.toString())}: AugmentedSubmittable<(${params.map(([full]): string => full).join(', ')}) => SubmittableExtrinsic<ApiType>>;`);
|
||||
}))
|
||||
.concat([indent(4)('};')]);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ import { TypeDef, TypeDefInfo } from '../../codec/types';
|
||||
import { Constructor, Registry } from '../../types';
|
||||
|
||||
import { isChildClass, isCompactEncodable } from './class';
|
||||
import { ClassOfUnsafe, getTypeDef } from '../../codec/create';
|
||||
import { ClassOf, ClassOfUnsafe, getTypeDef } from '../../codec/create';
|
||||
import AbstractInt from '../../codec/AbstractInt';
|
||||
import Compact from '../../codec/Compact';
|
||||
import Enum from '../../codec/Enum';
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vec from '../../codec/Vec';
|
||||
@@ -62,16 +63,13 @@ export function getSimilarTypes (definitions: object, registry: Registry, type:
|
||||
setImports(definitions, imports, ['IExtrinsic']);
|
||||
return ['IExtrinsic'];
|
||||
} else if (type === 'StorageKey') {
|
||||
// TODO We can do better
|
||||
return ['StorageKey', 'string', 'Uint8Array', 'any'];
|
||||
} else if (type === 'Address') {
|
||||
return ['Address', 'string', 'AccountId', 'AccountIndex', 'Uint8Array'];
|
||||
} else if (type === 'bool') {
|
||||
return ['bool', 'boolean', 'Uint8Array'];
|
||||
}
|
||||
|
||||
const instance = ClassOfUnsafe(registry, type);
|
||||
const clazz = ClassOfUnsafe(registry, type);
|
||||
|
||||
if (isChildClass(Vec, instance)) {
|
||||
if (isChildClass(Vec, clazz)) {
|
||||
const subDef = (getTypeDef(type).sub) as TypeDef;
|
||||
|
||||
if (subDef.info === TypeDefInfo.Plain) {
|
||||
@@ -85,17 +83,22 @@ export function getSimilarTypes (definitions: object, registry: Registry, type:
|
||||
} else {
|
||||
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (isChildClass(AbstractInt as unknown as Constructor<any>, instance) || isChildClass(Compact, instance)) {
|
||||
} else if (isChildClass(Enum, clazz)) {
|
||||
// TODO Handle this more gracefully (expand actual options)
|
||||
possibleTypes.push('number', 'any');
|
||||
} else if (isChildClass(AbstractInt as unknown as Constructor<any>, clazz) || isChildClass(Compact, clazz)) {
|
||||
possibleTypes.push('AnyNumber', 'Uint8Array');
|
||||
} else if (isChildClass(Struct, instance)) {
|
||||
} else if (isChildClass(ClassOf(registry, 'Address'), clazz)) {
|
||||
possibleTypes.push('string', 'AccountId', 'AccountIndex', 'Uint8Array');
|
||||
} else if (isChildClass(ClassOf(registry, 'bool'), clazz)) {
|
||||
possibleTypes.push('boolean', 'Uint8Array');
|
||||
} else if (isChildClass(Struct, clazz)) {
|
||||
possibleTypes.push('object', 'string', 'Uint8Array');
|
||||
} else if (isChildClass(Option, instance)) {
|
||||
} else if (isChildClass(Option, clazz)) {
|
||||
possibleTypes.push('null', 'object', 'string', 'Uint8Array');
|
||||
} else if (isChildClass(Uint8Array, instance)) {
|
||||
} else if (isChildClass(Uint8Array, clazz)) {
|
||||
possibleTypes.push('string', 'Uint8Array');
|
||||
} else if (isChildClass(String, instance)) {
|
||||
} else if (isChildClass(String, clazz)) {
|
||||
possibleTypes.push('string');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user