Bump common, string* with String (#2799)

* Bump common, string* with String

* Linting, TS 4.0.5
This commit is contained in:
Jaco Greeff
2020-10-28 14:28:49 +01:00
committed by GitHub
parent 3f48b3c29f
commit 1476e5e5e9
28 changed files with 128 additions and 122 deletions
+2 -2
View File
@@ -40,14 +40,14 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<strin
return {
docs: documentation,
name: stringCamelCase(name.toString()),
name: stringCamelCase(name),
type: returnType
};
});
return {
items,
name: stringCamelCase(name.toString())
name: stringCamelCase(name)
};
});
+2 -2
View File
@@ -91,14 +91,14 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
args,
docs: storageEntry.documentation,
entryType,
name: stringCamelCase(storageEntry.name.toString()),
name: stringCamelCase(storageEntry.name),
returnType
};
});
return {
items,
name: stringCamelCase(name.toString())
name: stringCamelCase(name)
};
});
+1 -1
View File
@@ -188,7 +188,7 @@ function generateInterfaces (definitions: Record<string, ModuleTypes>, { types }
};
return Object.entries(types).map(([name, type]): [string, string] => {
const def = getTypeDef(isString(type) ? type.toString() : JSON.stringify(type), { name });
const def = getTypeDef(isString(type) ? type : JSON.stringify(type), { name });
return [name, generators[def.info](definitions, def, imports)];
});
+3 -3
View File
@@ -19,7 +19,7 @@ const MAPPED_NAMES: Record<string, string> = {
};
function mapName (_name: Text): string {
const name = stringCamelCase(_name.toString());
const name = stringCamelCase(_name);
return MAPPED_NAMES[name] || name;
}
@@ -58,14 +58,14 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
return {
docs: documentation,
name: stringCamelCase(name.toString()),
name: stringCamelCase(name),
params
};
});
return {
items,
name: stringCamelCase(name.toString())
name: stringCamelCase(name)
};
});
+8 -8
View File
@@ -148,13 +148,13 @@ function addConstants (metadata: MetadataLatest): string {
.sort(sortByName)
.filter((moduleMetadata) => !moduleMetadata.constants.isEmpty)
.map((moduleMetadata) => {
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
const sectionName = stringLowerFirst(moduleMetadata.name);
return {
items: moduleMetadata.constants
.sort(sortByName)
.map((func) => {
const methodName = stringCamelCase(func.name.toString());
const methodName = stringCamelCase(func.name);
return {
interface: '`' + `api.consts.${sectionName}.${methodName}` + '`',
@@ -175,7 +175,7 @@ function addStorage (metadata: MetadataLatest): string {
.sort(sortByName)
.filter((moduleMetadata) => !moduleMetadata.storage.isNone)
.map((moduleMetadata) => {
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
const sectionName = stringLowerFirst(moduleMetadata.name);
return {
items: moduleMetadata.storage.unwrap().items
@@ -186,7 +186,7 @@ function addStorage (metadata: MetadataLatest): string {
: func.type.isDoubleMap
? ('`' + func.type.asDoubleMap.key1.toString() + ', ' + func.type.asDoubleMap.key2.toString() + '`')
: '';
const methodName = stringLowerFirst(func.name.toString());
const methodName = stringLowerFirst(func.name);
const outputType = unwrapStorageType(func.type, func.modifier.isOptional);
return {
@@ -217,13 +217,13 @@ function addExtrinsics (metadata: MetadataLatest): string {
.sort(sortByName)
.filter((meta) => !meta.calls.isNone && meta.calls.unwrap().length !== 0)
.map((meta) => {
const sectionName = stringCamelCase(meta.name.toString());
const sectionName = stringCamelCase(meta.name);
return {
items: meta.calls.unwrap()
.sort(sortByName)
.map((func) => {
const methodName = stringCamelCase(func.name.toString());
const methodName = stringCamelCase(func.name);
const args = Call.filterOrigin(func).map(({ name, type }) => `${name.toString()}: ` + '`' + type.toString() + '`').join(', ');
return {
@@ -258,7 +258,7 @@ function addEvents (metadata: MetadataLatest): string {
...(func.documentation.length && { summary: func.documentation })
};
}),
name: stringCamelCase(meta.name.toString())
name: stringCamelCase(meta.name)
})),
title: 'Events'
});
@@ -278,7 +278,7 @@ function addErrors (metadata: MetadataLatest): string {
name: error.name.toString(),
...(error.documentation.length && { summary: error.documentation })
})),
name: stringLowerFirst(moduleMetadata.name.toString())
name: stringLowerFirst(moduleMetadata.name)
})),
title: 'Errors'
});
+8 -4
View File
@@ -7,6 +7,7 @@ import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
import { getTypeDef } from '@polkadot/types/create';
import { paramsNotation } from '@polkadot/types/codec/utils';
import { isString } from '@polkadot/util';
import { setImports, ModuleTypes, TypeImports } from './imports';
import { readTemplate } from './file';
@@ -180,14 +181,17 @@ function formatVec (inner: string): string {
* Correctly format a given type
*/
/** @internal */
export function formatType (definitions: Record<string, ModuleTypes>, type: string | TypeDef, imports: TypeImports): string {
// eslint-disable-next-line @typescript-eslint/ban-types
export function formatType (definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports): string {
let typeDef: TypeDef;
if (typeof type === 'string') {
if (isString(type)) {
const _type = type.toString();
// If type is "unorthodox" (i.e. `{ something: any }` for an Enum input or `[a | b | c, d | e | f]` for a Tuple's similar types),
// we return it as-is
if (/(^{.+:.+})|^\([^,]+\)|^\(.+\)\[\]|^\[.+\]/.exec(type) && !/\[\w+;\w+\]/.exec(type)) {
return type;
if (/(^{.+:.+})|^\([^,]+\)|^\(.+\)\[\]|^\[.+\]/.exec(_type) && !/\[\w+;\w+\]/.exec(_type)) {
return _type;
}
typeDef = getTypeDef(type);