Allow config module to handle multiple validation
jackykwandesign opened this issue · 1 comments
jackykwandesign commented
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
The orginal validate function take 1 validate files only
And thats not good to seperate validation for different service
Describe the solution you'd like
export type ValidateFunction = (config: Record<string, any>) => Record<string, any>
export const validateMultiple = (validateFunctions:ValidateFunction[]) => (config: Record<string, unknown>) =>{
let finalOutput = {}
validateFunctions.forEach(validateFunction => {
const result = validateFunction(config)
finalOutput = {
...finalOutput,
...result
}
});
return finalOutput
}
app.module.ts
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load:[configuration],
validate:validateMultiple([validateSystemConfig, validateDBConfig])
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Teachability, documentation, adoption, migration strategy
we can add validateMultiple in forRoot option, or add this as a util in @nestjs/config package
What is the motivation / use case for changing the behavior?
allow config module to seperate validation for different service
kamilmysliwiec commented
Thanks for your suggestion!
There are no plans to implement it in the foreseeable future.
If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.