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

Simplify validation in domain #16

Open
mttschltz opened this issue Feb 8, 2022 · 1 comment
Open

Simplify validation in domain #16

mttschltz opened this issue Feb 8, 2022 · 1 comment
Labels
code quality Tests, linting

Comments

@mttschltz
Copy link
Owner

mttschltz commented Feb 8, 2022

Problem

Validation in the domain isn't easy to maintain

  • On creation, class-validator decorators validate simple properties
  • Custom validators validate complex (interface) properties
    • The current implementation of this is weak as it uses the (below mentioned) type guard, which only checks property existence. However, it may be a reasonable assumption that at runtime all such interfaces were created from factory functions and thus are valid anyway
  • A type guard validates the type

Ideally the entity could have its structure and type validated in one place.

@mttschltz mttschltz added the code quality Tests, linting label Feb 8, 2022
@mttschltz
Copy link
Owner Author

mttschltz commented Feb 8, 2022

The current implementation of this is weak as it uses the (below mentioned) type guard, which only checks property existence.

One idea to improve this is to use recursion. E.g. the custom validator uses the factory function to construct an entity from a class. The entity would then be validated.

Though could this lead to an infinite loop? E.g. a child validates a parent, which validates it's children, and so on.

However, it may be a reasonable assumption that at runtime all such interfaces were created from factory functions and thus are valid anyway

Maybe this is enough after all.

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

No branches or pull requests

1 participant