Additional typegen asserts (#2448)

* Additional typegen asserts

* typo

* Revert tuple assert

* Free-standing Vec is valid
This commit is contained in:
Jaco Greeff
2020-07-25 13:47:34 +02:00
committed by GitHub
parent 40cd9ff51f
commit 1cf4d6b9b8
12 changed files with 92 additions and 71 deletions
+1 -1
View File
@@ -30,7 +30,7 @@
"@polkadot/api": "1.26.0-beta.1",
"@polkadot/rpc-core": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"bn.js": "^5.1.2",
"rxjs": "^6.6.0"
}
+3 -3
View File
@@ -32,13 +32,13 @@
"@polkadot/rpc-core": "1.26.0-beta.1",
"@polkadot/rpc-provider": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util-crypto": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"@polkadot/util-crypto": "^3.0.0-beta.3",
"bn.js": "^5.1.2",
"memoizee": "^0.4.14",
"rxjs": "^6.6.0"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1"
"@polkadot/keyring": "^3.0.0-beta.3"
}
}
+4 -4
View File
@@ -28,19 +28,19 @@
"dependencies": {
"@babel/runtime": "^7.10.5",
"@polkadot/api-derive": "1.26.0-beta.1",
"@polkadot/keyring": "^2.18.1",
"@polkadot/keyring": "^3.0.0-beta.3",
"@polkadot/metadata": "1.26.0-beta.1",
"@polkadot/rpc-core": "1.26.0-beta.1",
"@polkadot/rpc-provider": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/types-known": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util-crypto": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"@polkadot/util-crypto": "^3.0.0-beta.3",
"bn.js": "^5.1.2",
"eventemitter3": "^4.0.4",
"rxjs": "^6.6.0"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1"
"@polkadot/keyring": "^3.0.0-beta.3"
}
}
+3 -3
View File
@@ -29,11 +29,11 @@
"@babel/runtime": "^7.10.5",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/types-known": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util-crypto": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"@polkadot/util-crypto": "^3.0.0-beta.3",
"bn.js": "^5.1.2"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1"
"@polkadot/keyring": "^3.0.0-beta.3"
}
}
+2 -2
View File
@@ -30,11 +30,11 @@
"@polkadot/metadata": "1.26.0-beta.1",
"@polkadot/rpc-provider": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"memoizee": "^0.4.14",
"rxjs": "^6.6.0"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1"
"@polkadot/keyring": "^3.0.0-beta.3"
}
}
+3 -3
View File
@@ -29,15 +29,15 @@
"@babel/runtime": "^7.10.5",
"@polkadot/metadata": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util-crypto": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"@polkadot/util-crypto": "^3.0.0-beta.3",
"bn.js": "^5.1.2",
"eventemitter3": "^4.0.4",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.31"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1",
"@polkadot/keyring": "^3.0.0-beta.3",
"mock-socket": "^9.0.3",
"nock": "^13.0.2"
}
+1 -1
View File
@@ -40,7 +40,7 @@
"@polkadot/metadata": "1.26.0-beta.1",
"@polkadot/rpc-provider": "1.26.0-beta.1",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"handlebars": "^4.7.6",
"websocket": "^1.0.31",
"yargs": "^15.4.1"
+17 -11
View File
@@ -92,18 +92,22 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
const Clazz = ClassOfUnsafe(registry, type);
if (isChildClass(Vec, Clazz)) {
const subDef = (getTypeDef(type).sub) as TypeDef;
const vecDef = getTypeDef(type);
const subDef = (vecDef.sub) as TypeDef;
if (subDef.info === TypeDefInfo.Plain) {
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
} else if (subDef.info === TypeDefInfo.Tuple) {
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
getSimilarTypes(definitions, registry, type, imports).join(' | ')
);
// this could be that we define a Vec type and refer to it by name
if (subDef) {
if (subDef.info === TypeDefInfo.Plain) {
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
} else if (subDef.info === TypeDefInfo.Tuple) {
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
getSimilarTypes(definitions, registry, type, imports).join(' | ')
);
possibleTypes.push(`([${subs.join(', ')}])[]`);
} else {
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
possibleTypes.push(`([${subs.join(', ')}])[]`);
} else {
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
}
}
} else if (isChildClass(Enum, Clazz)) {
const e = new (Clazz as Constructor)(registry) as Enum;
@@ -141,8 +145,10 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
} else if (isChildClass(String, Clazz)) {
possibleTypes.push('string');
} else if (isChildClass(Tuple, Clazz)) {
const subDef = getTypeDef(type).sub;
const tupDef = getTypeDef(type);
const subDef = tupDef.sub;
// this could be that we define a Tuple type and refer to it by name
if (Array.isArray(subDef)) {
const subs = subDef.map(({ type }) => getSimilarTypes(definitions, registry, type, imports).join(' | '));
+1 -1
View File
@@ -28,7 +28,7 @@
"dependencies": {
"@babel/runtime": "^7.10.5",
"@polkadot/types": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"bn.js": "^5.1.2"
},
"devDependencies": {
+3 -3
View File
@@ -28,15 +28,15 @@
"dependencies": {
"@babel/runtime": "^7.10.5",
"@polkadot/metadata": "1.26.0-beta.1",
"@polkadot/util": "^2.18.1",
"@polkadot/util-crypto": "^2.18.1",
"@polkadot/util": "^3.0.0-beta.3",
"@polkadot/util-crypto": "^3.0.0-beta.3",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.2",
"memoizee": "^0.4.14",
"rxjs": "^6.6.0"
},
"devDependencies": {
"@polkadot/keyring": "^2.18.1",
"@polkadot/keyring": "^3.0.0-beta.3",
"@types/memoizee": "^0.4.4"
}
}