-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom validation extension/custom accessor before as
check.
#159
Comments
@PizzaPartyInc (great username BTW), can you expand on why you need this feature? I'm leaning towards thinking this isn't a problem for env-var to solve. I would generally expect variable names to be defined and known in advance, and env-var is purely used to read and coerce them. |
In our concrete case, we have In the resulting The proposal to have a middleware checker is to make sure that when the app is launched - the placeholders are actually replaced with concrete values, and if not - throw an error, let the developer know that he needs to adjust the config. Yes, such things can be checked explicitly, before env-var calls, but it would look a bit... strange. E.g. in actual app code, we never call something like |
Hey!
I know there is already an option to add custom accessors, but those are only going at the end of the evaluation chaing. I'm interested in sort of a middleware approach.
An example scenario would be - We have a .env file like this:
For app to be used, placeholder must be replaced with an actual value, which shall be evaluated as a specific enum. So, a custom check is needed in addition to
.required()
and.asEnum
, e.g. something like this:The idea is that you want to check the original value first, and then proceed to type assertion. After checking the examples and source code I was not able to find a way to achieve this with the current implementation. If this is indeed possible - it would be nice to update the readme/examples.
Thanks!
The text was updated successfully, but these errors were encountered: