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(sequelize): extend Inclusion interface with "required" property #10192

Merged

Conversation

KalleV
Copy link
Contributor

@KalleV KalleV commented Nov 16, 2023

Partial fix for: #10193

This resolves Typescript errors such as the following when trying to use the new property with a repository call using "find", "findOne", "findById":

Type '{ relation: string; scope: { where: { id: number; }; }; required: true; }'
is not assignable to type 'InclusionFilter'.
  Object literal may only specify known properties, and 'required'
does not exist in type 'Inclusion'.

53           required: true

Reference:
https://loopback.io/pages/en/lb4/readmes/loopback-next/extensions/sequelize/

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

This resolves errors such as the following when trying to use the
new property with a repository call:
```ts
Type '{ relation: string; scope: { where: { id: number; }; }; required: true; }'
is not assignable to type 'InclusionFilter'.
  Object literal may only specify known properties, and 'required'
does not exist in type 'Inclusion'.

53           required: true
```

Signed-off-by: KalleV <[email protected]>
@coveralls
Copy link

coveralls commented Nov 16, 2023

Pull Request Test Coverage Report for Build 6983324259

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 110 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.007%) to 57.036%

Files with Coverage Reduction New Missed Lines %
packages/repository/src/relations/belongs-to/belongs-to.repository.ts 6 48.94%
packages/repository/src/relations/has-one/has-one.inclusion-resolver.ts 9 55.26%
packages/repository/src/relations/has-one/has-one.repository.ts 22 24.65%
packages/repository/src/relations/has-many/has-many-through.repository.ts 73 0.61%
Totals Coverage Status
Change from base Build 6886297667: -0.007%
Covered Lines: 9563
Relevant Lines: 12457

💛 - Coveralls

Comment on lines 6 to 8
declare module '@loopback/repository' {
interface Inclusion {
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it need to affect the types of core repository module, instead of type extension in the Sequelize repository itself. For the respective methods (find(), findOne(), and findById()).

I'm not certain about the behaviour this code will have but It can reflect to non sequelize repositories as well, which might not be intended here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shubhamp-sf Thanks for reviewing this. Yes, the TS declaration merging approach affects non-sequelize repositories too. Extending the method interfaces is much better, however, it doesn't cover the relation query "find" case like:

myRepository(foreignKey).find({
  include: [
    {
      // ...
      required: true
    }
  ]
}

I tried a couple of approaches for that case. Perhaps defining new interfaces like "SequelizeHasManyRepositoryFactory" that extend the find method in the underlying interfaces such as HasManyRepository?

@KalleV KalleV requested a review from shubhamp-sf November 24, 2023 16:18
Copy link
Contributor

@shubhamp-sf shubhamp-sf left a comment

Choose a reason for hiding this comment

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

LGTM

@dhmlau
Copy link
Member

dhmlau commented Dec 1, 2023

@shubhamp-sf, I'm merging this PR based on your approval as you're the code owner.

@dhmlau dhmlau merged commit 39e45fb into loopbackio:master Dec 1, 2023
13 checks passed
@dhmlau
Copy link
Member

dhmlau commented Dec 1, 2023

@KalleV, thanks for your contribution. Your PR has landed! 🎉

@KalleV KalleV deleted the KalleV-fix-inclusion-filter-type-error branch December 6, 2023 18:09
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

Successfully merging this pull request may close these issues.

4 participants