Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmn): clean up BaseServiceV2 options
Cleans up the system of options for BaseServiceV2. Includes some refactoring to reduce the size of base-service-v2.ts. Primary change from a user point of view is that standard options and regular options get merged. Makes it more clear how user inputted options will override defaults provided by the service.
- Loading branch information
1 parent
9b74fd6
commit 9b28918
Showing
16 changed files
with
208 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@eth-optimism/common-ts': minor | ||
'@eth-optimism/drippie-mon': minor | ||
'@eth-optimism/fault-detector': minor | ||
'@eth-optimism/replica-healthcheck': minor | ||
'@eth-optimism/data-transport-layer': patch | ||
--- | ||
|
||
Refactors BaseServiceV2 slightly, merges standard options with regular options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ValidatorSpec, Spec } from 'envalid' | ||
|
||
import { LogLevel } from '../common/logger' | ||
import { validators } from './validators' | ||
|
||
/** | ||
* Options for a service. | ||
*/ | ||
export type Options = { | ||
[key: string]: any | ||
} | ||
|
||
/** | ||
* Specification for options. | ||
*/ | ||
export type OptionsSpec<TOptions extends Options> = { | ||
[P in keyof Required<TOptions>]: { | ||
validator: (spec?: Spec<TOptions[P]>) => ValidatorSpec<TOptions[P]> | ||
desc: string | ||
default?: TOptions[P] | ||
public?: boolean | ||
} | ||
} | ||
|
||
/** | ||
* Standard options shared by all services. | ||
*/ | ||
export type StandardOptions = { | ||
loopIntervalMs?: number | ||
port?: number | ||
hostname?: string | ||
logLevel?: LogLevel | ||
} | ||
|
||
/** | ||
* Specification for standard options. | ||
*/ | ||
export const stdOptionsSpec: OptionsSpec<StandardOptions> = { | ||
loopIntervalMs: { | ||
validator: validators.num, | ||
desc: 'Loop interval in milliseconds, only applies if service is set to loop', | ||
default: 0, | ||
public: true, | ||
}, | ||
port: { | ||
validator: validators.num, | ||
desc: 'Port for the app server', | ||
default: 7300, | ||
public: true, | ||
}, | ||
hostname: { | ||
validator: validators.str, | ||
desc: 'Hostname for the app server', | ||
default: '0.0.0.0', | ||
public: true, | ||
}, | ||
logLevel: { | ||
validator: validators.logLevel, | ||
desc: 'Log level', | ||
default: 'debug', | ||
public: true, | ||
}, | ||
} | ||
|
||
/** | ||
* Gets the list of public option names from an options specification. | ||
* | ||
* @param optionsSpec Options specification. | ||
* @returns List of public option names. | ||
*/ | ||
export const getPublicOptions = ( | ||
optionsSpec: OptionsSpec<Options> | ||
): string[] => { | ||
return Object.keys(optionsSpec).filter((key) => { | ||
return optionsSpec[key].public | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Router } from 'express' | ||
|
||
/** | ||
* Express router re-exported. | ||
*/ | ||
export type ExpressRouter = Router |
Oops, something went wrong.