Comments (11)
I can't seem to reproduce this with my minimal test case (below). What is the value of ITierEnum in your case? I'm guessing it's a string enum?
const env = envalid.cleanEnv(process.env, {
POLICIES: envalid.json({
default: JSON.stringify({
bP: {
free: { users: 1, monthly: 0, annually: 0 },
basic: { users: 1, monthly: 0, annually: 0 },
}
})
}),
})
from envalid.
My configuration works in 7.2 but not anymore in 7.3.
/** The tier of the Organization */
export declare const enum ITierEnum {
free = "free",
basic = "basic",
premium = "premium",
enterprise = "enterprise"
}
from envalid.
Hmm, the following test case still works for me using the enums:
const enum ITierEnum {
free = "free",
basic = "basic",
premium = "premium",
enterprise = "enterprise"
}
const env = envalid.cleanEnv(process.env, {
POLICIES: envalid.json({
default: JSON.stringify({
bP: {
[ITierEnum.free]: { users: 1, monthly: 0, annually: 0 },
[ITierEnum.basic]: { users: 1, monthly: 0, annually: 0 },
}
})
}),
Could you share some more of the traceback of that error? Are you using any custom middlewares?
from envalid.
I just updated envalid to version 7.3.0 and noticed some environment variables relying on default values breaking with the update. I think it's related to this change: ef5a895
Previously, a default value for a custom validator doing eg. JSON parsing would be ran through that validator, causing issues if you tried to define the default value as an object (but satisfying TypeScript typings for the validator). Instead, we had to define the default values as strings, so that they could be properly parsed by the validator.
from envalid.
@Pinqvin could you post a minimal repro case here?
from envalid.
https://github.com/Pinqvin/envalid-repro With [email protected] the values you get for TEST
and TEST_CUSTOM
are objects, but when you upgrade to 7.3.0, you get string values out. This is what lead to unexpected runtime behaviour, when I upgraded to 7.3.0
from envalid.
Thank you @Pinqvin for that, I think you are correct and this is unfortunately a breaking change that I should have highlighted:
default values are not passed through validation logic, they are default *output* values.
So if you have default values for json
variables, the default value should be want you want to appear in the output, not an unparsed string value. There is more context on #176. Sorry for the inconvenience here, hope you're able to migrate your default values over without issues
from envalid.
@af Is that an intended change? When we pass a JSON stringify to env, we expect it to be an Object
value instead of a string. Is that an intended change in v7.3? I think this is a bug to be addressed. This has been a big setback for using JSON type.
from envalid.
The change should only apply to provided default values, the actual strings passed in through the env vars should still be converted from string -> object via JSON.parse as before. If that is not happening for you somehow please let me know
from envalid.
@af Is not the output of the config is string
not object
? It doesn't relate to the input default value or not.
from envalid.
@veeramarni the output of the config should be the same as before, if the value is being provided from an actual env var. For example:
given this foo.ts:
const env = envalid.cleanEnv(process.env, {
K: envalid.json(),
})
console.log(typeof env.K, env.K)
Running K='{"foo": 234}' ts-node foo.ts
prints object { foo: 234 }
as expected for me. If you have a repro case where it doesn't work like that please share it.
Regarding the initial issue you posted here, if you remove the JSON.stringify()
in your default value I would think your example should work as expected on 7.3.0?
from envalid.
Related Issues (20)
- Help with Next.js HOT 5
- ts-expect-error problem with 7.2.1 HOT 4
- Make an optional case-insensitive flag HOT 2
- NPM package is not valid HOT 3
- Support `structuredClone` HOT 3
- How to access desc HOT 2
- Add parse options to str() HOT 1
- array validator HOT 1
- Add option to load validator specs from .example.env file HOT 1
- Access value of env object by name HOT 1
- envalid in react-native for preview crashes without giving description of missing env HOT 2
- testOnly setting variable to Symbol instead of failing HOT 5
- Pick from validators HOT 2
- str({ devDefault: undefined }) generates an incorrect type HOT 2
- Require environment variables only if `NODE_ENV` is not set to `test` HOT 2
- Skipping env var validation in tests HOT 1
- Prevent process exit during tests HOT 1
- makeExactValidator is not exported HOT 1
- Combine envalid with Docker secrets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envalid.