(yargs: Args, nameMapping: Record<string, string> = {})
| 49 | } |
| 50 | |
| 51 | export function yargsToIConfig(yargs: Args, nameMapping: Record<string, string> = {}): Partial<IConfig> { |
| 52 | return Object.entries(yargs).reduce((acc, [key, value]) => { |
| 53 | if (['_', '$0'].includes(key)) return acc; |
| 54 | |
| 55 | const outputKey = nameMapping[key] ?? camelCase(key); |
| 56 | |
| 57 | if (outputKey === 'networkRegistry') { |
| 58 | try { |
| 59 | value = JSON.parse(value as string); |
| 60 | } catch (e) { |
| 61 | throw new Error('Argument `network-registry` is not valid JSON'); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Merge network endpoints and possible endpoint configs |
| 66 | if (outputKey === 'networkEndpoint') { |
| 67 | const endpointConfig = processEndpointConfig(yargs['network-endpoint-config']); |
| 68 | if (typeof value === 'string') { |
| 69 | value = [value]; |
| 70 | } |
| 71 | if (Array.isArray(value)) { |
| 72 | value = value.reduce( |
| 73 | (acc, endpoint, index) => { |
| 74 | acc[endpoint] = endpointConfig[index] ?? {}; |
| 75 | return acc; |
| 76 | }, |
| 77 | {} as Record<string, IEndpointConfig> |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | if (outputKey === 'primaryNetworkEndpoint') { |
| 82 | const endpointConfig = processEndpointConfig(yargs['primary-network-endpoint-config']); |
| 83 | value = [value, endpointConfig[0] ?? {}]; |
| 84 | } |
| 85 | if (['networkEndpointConfig', 'primaryNetworkEndpointConfig'].includes(outputKey)) return acc; |
| 86 | |
| 87 | if (outputKey === 'disableHistorical' && value) { |
| 88 | acc.historical = false; |
| 89 | } |
| 90 | if (outputKey === 'historical' && value === 'false') { |
| 91 | value = false; |
| 92 | } |
| 93 | |
| 94 | acc[outputKey] = value; |
| 95 | return acc; |
| 96 | }, {} as any); |
| 97 | } |
| 98 | |
| 99 | function warnDeprecations(argv: Args) { |
| 100 | if (argv['subquery-name']) { |
no test coverage detected