Additional typegen asserts (#2448)
* Additional typegen asserts * typo * Revert tuple assert * Free-standing Vec is valid
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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(' | '));
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user