core
core copied to clipboard
Config loader upgrades
🪤 Context
Want to adjust the config loader pattern to be easier to use / interact with. In practical projects, the method implemented for swapping out the config loader / providing a new one just isn't easy to interact with. In large part because it uses a pattern that is completely foreign in this project
Create internal.config
This gets used surprisingly often (for my stuff at least), and going into internal.boilerplate.configuration is wordy
Loader definitions
- Add the ability to define addition methods
declare module ... {
export interface ConfigLoadersOrSomething {
keyvault: true;
}
}
- Create runtime definitions
function KeyvaultLoader({ internal }: TServiceParams) {
// passed in a list of definitions to load for
internal.config.loader("keyvault", async (loadConfigs: ConfigDefinition[]) => {
// not requested properties will be rejected w/ warnings
return PARTAL_CONFIG_TO_MERGE;
});
}
- Add flags to boot options:
APP.boostrap({
// everything is default true if not specified
config: boolean | { env?: boolean, file?: boolean, argv?: boolean, keyvault?: boolean }
});
Reload method
Add internal.config.reload() method to re-run the config process. It will re-run all the config loaders, updating the values in config, and finally emitting an event
Flag expected config method
- passed as string = only that method (special exception: "*", alias for all)
- array = any of
- false = does not load (library calculates and uses
onPreInitto get ahead) - undefined = all of
CreateLibrary({
configuration: {
CONFIG_FILE: {
type: "string",
source: "argv"
},
MAGIC_API_KEY: {
type: "string",
source: ["env", "keyvault"]
}
}
})