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

Enhancing Global Data Validation Capabilities in Celest #41

Open
X-SLAYER opened this issue Feb 9, 2024 · 0 comments
Open

Enhancing Global Data Validation Capabilities in Celest #41

X-SLAYER opened this issue Feb 9, 2024 · 0 comments
Labels
triaging Initial investigation into the issue

Comments

@X-SLAYER
Copy link

X-SLAYER commented Feb 9, 2024

Overview

Backend development requires robust data validation to protect against invalid or harmful data. With increasing application complexity, advanced, user-friendly methods are needed. Celest's strong backend foundation could be enhanced with a specialized package like ez_validator

Proposed Solution: ez_validator

ez_validator stands out as an exemplary solution for several reasons:

  • Simplicity and Power: Inspired by the simplicity and effectiveness of yup/joi. offers an intuitive yet powerful API for Flutter, making complex validations more accessible.
  • Flexibility: It supports a wide range of validations, from basic type checking to more complex, schema-based validation scenarios.
  • Middleware Integration: ez_validator could be seamlessly integrated as part of a middleware layer in Celest, offering a standardized way to validate data before it reaches the business logic layer.

Implementation Use Cases

  • Validation in Request Body Processing
  • Ensuring request bodies meet predefined criteria.
  • Enforcing validation rules on request headers.
  • Facilitating middleware-based validation approach.
  • Enhancing code maintainability and readability.

Benefits to Celest

  • ez_validator would help minimize the risk of errors and security vulnerabilities.
  • ez_validator's straightforward API could significantly reduce the time and effort required to implement complex validation logic.

How EzValidator can help

ez_validator offers a dead-simple approach to field and object schema validation tailored for Flutter. Inspired by the intuitive API of Yup, ez_validator simplifies the process of defining and enforcing data schemas within your Flutter applications.

final bodySchema = EzSchema.shape({
  'name': EzValidator<String>()
      .transform((value) => value.trim())
      .minLength(3, 'Name must be at least 3 characters long.'),
  'password': EzValidator<String>()
      .minLength(8, 'Password must be at least 8 characters long.'),
  'confirmPassword': EzValidator<String>().when(
    'password',
    (confirmValue, [ref]) =>
        confirmValue == ref?['password'] ? null : 'Passwords do not match',
  )
})

/// Validate the coming data 
final errors = bodySchema.catchErrors(bodyDaya); // Example bodyDaya is a Map<String,String>

ez_validator handle complex validations

  final EzSchema userProfileSchema = EzSchema.shape({
    "firstName": EzValidator<String>().required(),
    "lastName": EzValidator<String>().required(),
    "email": EzValidator<String>().required().email(),
    "age": EzValidator<int>().min(18).max(100),
    'contactDetails': EzSchema.shape({
      'mobile': EzValidator<String>()
          .required()
          .matches(RegExp(r'^\+\d{10,15}$'), 'Invalid phone number'),
      'landline': EzValidator<String?>(optional: true),
    }),
    'level': EzValidator<String>(defaultValue: 'Beginner').required().oneOf([
      'Beginner',
      'Intermediate',
      'Advanced',
      'Expert',
    ]),
    'address': EzSchema.shape({
      'street': EzValidator<String>().required(),
      'city': EzValidator<String>().required(),
      'state': EzValidator<String>().required(),
      'zipCode': EzValidator<num>().required(),
      'country': EzSchema.shape({
        'name': EzValidator<String>(defaultValue: 'TUNISIA').required(),
        'code': EzValidator<String>().required(),
        'continent': EzSchema.shape({
          'name': EzValidator<String>().required(),
          'code': EzValidator<String>().required(),
        })
      }),
    }),
    'employment': EzSchema.shape({
      'current': EzValidator<String?>(optional: true),
      'previous': EzSchema.shape({
        'companyName': EzValidator<String>().required(),
        'position': EzValidator<String>().required(),
        'years': EzValidator<int>().min(1).max(50),
      }),
    }),
  });

I look forward to further discussions on this and am eager to contribute to the implementation of this feature.

@dnys1 dnys1 added the triaging Initial investigation into the issue label Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaging Initial investigation into the issue
Projects
None yet
Development

No branches or pull requests

2 participants