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

Validator over multiple values #35

Open
SunlightBro opened this issue Oct 9, 2024 · 0 comments
Open

Validator over multiple values #35

SunlightBro opened this issue Oct 9, 2024 · 0 comments

Comments

@SunlightBro
Copy link
Contributor

SunlightBro commented Oct 9, 2024

Feature Request

Consider a odm like this:

@firestoreSerializable
class TimeFrame {
  final Timestamp start;
  final Timestamp end;
  
  TimeFrame(this.lowerLimit, this.upperLimit) {
    _$assertTimeFrame(this);
  }
}

I would like to validate that start is before end.

Idea

abstract class ValidatorWithOther<T> {
  const ValidatorWithOther(this.otherPropertyName);
  final String otherPropertyName;

  void validate(Object? value, T other, String propertyName);
}

that could be extended

class IsAfterValidator extends ValidatorWithOther<Timestamp> {
  const IsAfterValidator(super.otherPropertyName);

  @override
  void validate(Object? value, Timestamp other, String propertyName) {
    // TODO: implement validate
  }
}

And then applied to a property

@firestoreSerializable
class TimeFrame {
  final Timestamp start;
  @IsAfterValidator('start')
  final Timestamp end;
  
  TimeFrame(this.lowerLimit, this.upperLimit) {
    _$assertTimeFrame(this);
  }
}

code generation should throw an exception if the other parameter with the correct Type does not exist.
(maybe even a custom_lint)

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

1 participant