core icon indicating copy to clipboard operation
core copied to clipboard

Config loader upgrades

Open zoe-codez opened this issue 1 year ago • 0 comments

🪤 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

  1. Add the ability to define addition methods
declare module ... {
  export interface ConfigLoadersOrSomething {
    keyvault: true; 
  }
}
  1. 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;
  });
}
  1. 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 onPreInit to get ahead)
  • undefined = all of
CreateLibrary({
  configuration: {
  	CONFIG_FILE: {
      type: "string",
	  source: "argv"
  	},
  	MAGIC_API_KEY: {
      type: "string",
	  source: ["env", "keyvault"]
  	}
  }
})

zoe-codez avatar Oct 06 '24 15:10 zoe-codez