Skip to content
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

Feature Idea: dependent variables #87

Closed
janl opened this issue Aug 22, 2018 · 3 comments
Closed

Feature Idea: dependent variables #87

janl opened this issue Aug 22, 2018 · 3 comments

Comments

@janl
Copy link

janl commented Aug 22, 2018

First of all, thank you for providing such a useful utility <3

In my scenario: I want to validate an optional username and password, but also say that if there is one without the other, the validation should fail. E.g. allow configuration against a resources that allows authenticated and unauthenticated requests. One can opt to add user/pass, or not user/pass, but if the provide user/pass, BOTH have to be there.

This can be solved in a transform function, which is what I’m going with for now, but something like this would be nice:

let config = {
  username: str(dependsOn:['password']),
  password: str(dependsOn: ['username'])
}

This is just to sketch what this could look like. Using an array of depends could open this up to more than two dependent variables. Although having to make the dependency on both sides will explode maintenance complexity quickly.

Alternatively, maybe this can be done with grouping:

let config = {
  group: {
    username: str(dependsOn:['password']),
    password: str(dependsOn: ['username'])
  }
}

where group is an arbitrary label, but the semantics are: if one of the values is missing, validation fails.

Another variant would be explicit grouping:

let config = {
  username: str(),
  password: str()
}

const options = {
  groups: [['username', 'password']]
}
envalid.cleanEnv(process.env, config, options)
@SimenB
Copy link
Collaborator

SimenB commented Aug 22, 2018

Duplicate of #78, isn't it?

@janl
Copy link
Author

janl commented Aug 22, 2018

totally 🤦‍♂️ I swear I looked through all open and closed issues for a discussion on this, but I must have missed it.

@janl janl closed this as completed Aug 22, 2018
@SimenB
Copy link
Collaborator

SimenB commented Aug 22, 2018

I still love the idea, would love for you to weigh in on that one 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants