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

add enforce.allOf compound for AND style requirements #521

Closed
ealush opened this issue Nov 23, 2020 · 0 comments · Fixed by #533
Closed

add enforce.allOf compound for AND style requirements #521

ealush opened this issue Nov 23, 2020 · 0 comments · Fixed by #533
Labels
enforce feature New feature or request good first issue Good for newcomers

Comments

@ealush
Copy link
Owner

ealush commented Nov 23, 2020

Similar to anyOf, we need an AND relationship rule: allOf.

In the following example value must both be a string and longer than 10.

enforce(value).allOf(
  enforce.longerThan(10),
  enforce.isString,
);

This can be even more useful when combined with templates and shape validations:

const User = enforce.template(
  enforce.loose({
    id: enforce.isNumber()
    name: enforce.shape({
      first: enforce.isString(),
      last: enforce.isString(),
      middle: enforce.optional(enforce.isString()),
    }),
  })
);

const DisabledAccount = enforce.template(
  enforce.loose({
    disabled: enforce.equals(true)
  })
)

enforce(value).allOf(
  User,
  DisabledAccount
);

Developer guidelines

  1. Create a new file called allOf right next to anyOf. It should be pretty much the same, implementing the rules.some logic with some other counter mechanism.

  2. To actually have it used by enforce, add it to this compounds export

  3. Add a new test file here and test different scenarios

  4. Add suitable types here and here (basically duplicate anyOf).

  5. If you feel like it, also add suitable docs for this feature here

@ealush ealush added feature New feature or request good first issue Good for newcomers enforce labels Nov 23, 2020
Moses3301 pushed a commit to Moses3301/vest that referenced this issue Nov 29, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 29, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 29, 2020
@ealush ealush linked a pull request Nov 30, 2020 that will close this issue
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
Moses3301 added a commit to Moses3301/vest that referenced this issue Nov 30, 2020
@ealush ealush linked a pull request Dec 1, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enforce feature New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant