(raw: unknown)
| 13 | } |
| 14 | |
| 15 | export function parseChainTypes(raw: unknown): ChainTypes { |
| 16 | const chainTypes = plainToClass(ChainTypes, raw); |
| 17 | if ( |
| 18 | !!chainTypes.types || |
| 19 | !!chainTypes.typesChain || |
| 20 | !!chainTypes.typesBundle || |
| 21 | !!chainTypes.typesAlias || |
| 22 | !!chainTypes.typesSpec |
| 23 | ) { |
| 24 | const errors = validateSync(chainTypes, {whitelist: true, forbidNonWhitelisted: true}); |
| 25 | if (errors?.length) { |
| 26 | // TODO: print error details |
| 27 | const errorMsgs = errors.map((e) => e.toString()).join('\n'); |
| 28 | throw new Error(`failed to parse chain types.\n${errorMsgs}`); |
| 29 | } |
| 30 | return chainTypes; |
| 31 | } else { |
| 32 | throw new Error(`chainTypes is not valid`); |
| 33 | } |
| 34 | } |
no test coverage detected