Commit e251dac4 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #5126 from ethereum-optimism/inphi/fix-svc

fix(cmn): BaseServiceV2 throws on camelCase options
parents 8272207c fecd42d6
---
'@eth-optimism/common-ts': patch
---
Fix BaseServiceV2 configuration for caseCase options
...@@ -211,8 +211,15 @@ export abstract class BaseServiceV2< ...@@ -211,8 +211,15 @@ export abstract class BaseServiceV2<
// Since BCFG turns everything into lower case, we're required to turn all of the input option // Since BCFG turns everything into lower case, we're required to turn all of the input option
// names into lower case for the validation step. We'll turn the names back into their original // names into lower case for the validation step. We'll turn the names back into their original
// names when we're done. // names when we're done.
const lowerCaseOptions = Object.entries(params.options).reduce(
(acc, [key, val]) => {
acc[key.toLowerCase()] = val
return acc
},
{}
)
const cleaned = cleanEnv<TOptions>( const cleaned = cleanEnv<TOptions>(
{ ...config.env, ...config.args, ...(params.options || {}) }, { ...config.env, ...config.args, ...(lowerCaseOptions || {}) },
Object.entries(params.optionsSpec || {}).reduce((acc, [key, val]) => { Object.entries(params.optionsSpec || {}).reduce((acc, [key, val]) => {
acc[key.toLowerCase()] = val.validator({ acc[key.toLowerCase()] = val.validator({
desc: val.desc, desc: val.desc,
......
import { validators } from '../dist'
import { BaseServiceV2 } from '../src'
type ServiceOptions = {
camelCase: string
}
class Service extends BaseServiceV2<ServiceOptions, {}, {}> {
constructor(options?: Partial<ServiceOptions>) {
super({
name: 'test-service',
version: '0.0',
options,
optionsSpec: {
camelCase: { validator: validators.str, desc: 'test' },
},
metricsSpec: {},
})
}
protected async main() {
/* eslint-disable @typescript-eslint/no-empty-function */
}
}
describe('BaseServiceV2', () => {
it('base service ctor does not throw on camel case options', async () => {
new Service({ camelCase: 'test' })
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment