Skip to content

fix(types): allow any values in isIn validator#12962

Merged
sdepold merged 6 commits into
sequelize:mainfrom
lukashroch:isIn-fix
Oct 24, 2021
Merged

fix(types): allow any values in isIn validator#12962
sdepold merged 6 commits into
sequelize:mainfrom
lukashroch:isIn-fix

Conversation

@lukashroch
Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Hi,

this is to update current types for isIn validator of validator.js lib. It should accept array of any values. It is then coerced to string regardless the content.
It updates both isIn and notIn signatures are both are using validator.js isIn.
This is e.g. useful when model's column is number and you're validating against list of numbers.

Reference:

Copy link
Copy Markdown
Member

@papb papb left a comment

Choose a reason for hiding this comment

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

Hello! I see you are a first-time contributor, thank you for taking the time to help Sequelize! I hope to see more PRs from you in the future!

Please add at least one test to make sure your implementation works as intended and to prevent regressions in the future. For good examples on how to test typescript typings, check the following PRs: 11368, 11379, 11520, 13042. You can also use expect-type if you need more complex assertions for your test.

@papb papb added status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. labels Jun 25, 2021
@lukashroch lukashroch requested a review from papb June 25, 2021 18:19
@lukashroch
Copy link
Copy Markdown
Contributor Author

No problem, added couple of tests. I haven't found any other tests for validators (type tests looks bit random), so hope this place is OK. Let me know if anything needs amending.

@github-actions github-actions Bot removed the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Jun 25, 2021
@sdepold sdepold self-assigned this Oct 16, 2021
Comment thread types/test/validators.ts
email: {
type: DataTypes.STRING,
validate: {
notIn: [['second', 2, null]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would have somehow expected that we would have e.g. an INTEGER column and hence verify that the value is no part of a list of numbers or so.

Also, is that syntax correct? Why array of array and not ['first', 1, null]

Copy link
Copy Markdown
Contributor Author

@lukashroch lukashroch Oct 16, 2021

Choose a reason for hiding this comment

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

test was written to demonstrate that type works, i.e. it accepts other types not just string. Real world would be different, as you say e.g. list of int and int data type.

Syntax is how sequelize implements it (https://github.com/sequelize/sequelize/blob/main/types/lib/model.d.ts#L1112 or https://sequelize.org/master/manual/validations-and-constraints.html), I haven't really change that. Just a type since validator.js allows any for this validation.

@sdepold sdepold merged commit d511d91 into sequelize:main Oct 24, 2021
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

aliatsis pushed a commit to creditiq/sequelize that referenced this pull request Jun 2, 2022
* fix(types): allow any values in `isIn` validator

* test(types): isIn/notIn validation type tests

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants