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

fix(types): accept $nested.syntax$ in WhereAttributeHash #13983

Merged
merged 20 commits into from Feb 5, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Jan 21, 2022

Pull Request Checklist

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

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

Description Of Change

Tiny change that has become possible since we dropped TS < 4.1:
User.findOne({ where: { '$nested.column$': 'blah2' } }) is not reported as an error by TypeScript anymore.

Closes #13288

TODO

  • Check whether $name$ is valid
  • Check whether $include.include.name$ is valid
  • Add tests for nested nested include

@ephys ephys added the type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. label Jan 21, 2022
@ephys ephys self-assigned this Jan 21, 2022
@ephys
Copy link
Member Author

ephys commented Jan 21, 2022

TypeScript < 4.4 does not support using Template Literal Types as keys so I had to ts-ignore both the test & the implementation - but it doesn't cause issues in ts < 4.4 and works in ts >= 4.4

We can enable it again on 2022-05-26 when we drop support for TS < 4.4

@ephys
Copy link
Member Author

ephys commented Jan 22, 2022

I think with some more black magic we should be able to typecheck include.where too, but I'll keep it for a follow-up PR

User.findOne({
  include: [{
    association: User.associations.group,
    where: {
      // these are not currently type-checked
      test: 'test',
    }
  }],
});

@ephys ephys marked this pull request as ready for review January 22, 2022 12:28
@ephys ephys marked this pull request as draft January 22, 2022 14:59
@ephys ephys marked this pull request as ready for review January 22, 2022 17:22
@ephys
Copy link
Member Author

ephys commented Jan 31, 2022

This PR should also include support for the JSON nested key syntax https://sequelize.org/v4/manual/tutorial/querying.html#nested-key

I can't find the documentation on that syntax for v6. Is it still a thing?

It's looking like it's not and was replaced with sequelize.json

Edit: I've found a place where it was used in order: https://github.com/sequelize/sequelize/blob/main/test/integration/model/json.test.js#L573

Edit 2: And in where, so it's still a thing https://github.com/sequelize/sequelize/blob/main/test/integration/model/json.test.js#L117

We should improve the documentation to reflect this

I wonder if $nested.column$.nested.json.property works. That would impact #13992

@WikiRik
Copy link
Member

WikiRik commented Jan 31, 2022

This PR should also include support for the JSON nested key syntax https://sequelize.org/v4/manual/tutorial/querying.html#nested-key

I can't find the documentation on that syntax for v6. Is it still a thing?

It seems that it got lost in #11825

@ephys ephys changed the title fix(types): accept nested columns syntax in WhereAttributeHash fix(types): accept $nested.syntax$ / json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ / json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash Jan 31, 2022
@ephys ephys changed the title fix(types): accept $nested.syntax$ and json.syntax in WhereAttributeHash fix(types): accept $nested.syntax$ in WhereAttributeHash Jan 31, 2022
@ephys
Copy link
Member Author

ephys commented Jan 31, 2022

I'll open a follow-up PR for the json.syntax as the typing I have in mind is a bit complicated

@ephys
Copy link
Member Author

ephys commented Feb 2, 2022

As the only issue is that the false-positive is still present in TS < 4.4, I think I'll merge this (tomorrow or friday to still leave some time to react). Then we can fix #14038, and then open a follow-up PR that uses typesVersion to provide an alternative typing for TS < 4.4

@WikiRik
Copy link
Member

WikiRik commented Feb 2, 2022

Sounds good! We should also publish a new alpha release of v7 after we merged all these typing PRs

@ephys
Copy link
Member Author

ephys commented Feb 4, 2022

@WikiRik @allawesome497 if you're ok with the above plan, can I get one of your review approvals? :)

@ephys ephys merged commit f72bb1e into main Feb 5, 2022
@ephys ephys deleted the ephys/find-accepts-include-reference branch February 5, 2022 00:54
@ephys ephys mentioned this pull request Feb 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2022

🎉 This PR is included in version 7.0.0-alpha.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

aliatsis pushed a commit to creditiq/sequelize that referenced this pull request Jun 2, 2022
vanthome pushed a commit to vanthome/sequelize that referenced this pull request Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @v7 type: 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.

TypeScript complains about $nested.column$ syntax in query where clause.
4 participants