Skip to content

fix: Add ValidationMetadata.name to IsOptional #2044

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

Merged
merged 6 commits into from
Jan 15, 2024

Conversation

Clashsoft
Copy link
Contributor

@Clashsoft Clashsoft commented Apr 13, 2023

Description

This makes it easier to detect the presence of the IsOptional decorator.

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Workaround

The presence of the IsOptional decorator, given ValidationMetadata, can be checked with a blackbox test of the constraint.

  isIsOptional(m: ValidationMetadata) {
    if (m.type !== ValidationTypes.CONDITIONAL_VALIDATION) {
      return false;
    }
    const constraint = m.constraints?.[0];
    // black box testing
    return constraint
      && constraint({[m.propertyName]: null}, null) === false
      && constraint({[m.propertyName]: undefined}, undefined) === false
      && constraint({[m.propertyName]: ''}, '') === true
      && constraint({[m.propertyName]: ' '}, ' ') === true
      && constraint({[m.propertyName]: 0}, 0) === true
      && constraint({[m.propertyName]: false}, false) === true
      && constraint({[m.propertyName]: true}, true) === true
      ;
  }

This makes it easier to detect the presence of the IsOptional decorator.
@Clashsoft Clashsoft changed the title Add ValidationMetadata.name to IsOptional fix: Add ValidationMetadata.name to IsOptional Apr 13, 2023
@Pigrabbit
Copy link

I'm looking forward to getting this PR to be merged 👀

@Clashsoft
Copy link
Contributor Author

I'd like to bump this. It is a simple change without any potential negative impact.

Copy link
Member

@braaar braaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@braaar braaar merged commit e40571f into typestack:develop Jan 15, 2024
@Clashsoft Clashsoft deleted the patch-1 branch January 15, 2024 07:45
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants