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

Remove Dynamoose interfaces #76

Open
MickL opened this issue May 4, 2020 · 15 comments
Open

Remove Dynamoose interfaces #76

MickL opened this issue May 4, 2020 · 15 comments
Labels
wait for others Wait for others

Comments

@MickL
Copy link
Contributor

MickL commented May 4, 2020

Could you please remove all interfaces related to Dynamoose?

It now has its own type definitions and it could happen that the IDE imports typings from nestjs-dynamoose by mistake and those type definitions are deprecated.

I have used: 0.2.0-beta.2

Also readme should be updated: Model should not be imported from nestjs-dynamoose but from dynamoose

@MickL
Copy link
Contributor Author

MickL commented May 4, 2020

Or maybe Model should be kept in nestjs-dynamoose if it is/behaves differently but then it should extend interfaces from dynamoose if possible. The best would be if one does not have to keep nestjs-dynamoose interfaces manually in sync with dynamoose interfaces.

E.g. in your QueryInterface the functions descending and ascending do not exist in Dynamoose 2.x. But there will be a new sort function: dynamoose/dynamoose#860

@hardyscc
Copy link
Owner

hardyscc commented May 4, 2020

the current Model interface from dynamoose is still broken, therefore I need to maintain a copy here, however I will review the interfaces and match the new v2 api as much as possible.

@MickL
Copy link
Contributor Author

MickL commented May 4, 2020

Could you explain what you mean by broken?

I will review the interfaces and match the new v2 api as much as possible

Thanks for your efforts!

Even tho he released 2.x it seems to be still in beta and changes and fixes are currently common. I am kind of afraid that changes made are not reflected in this project if there is a copy. It could be even in years that Dynamoose gets updated but this package is no more maintained so I hope one day this package will not redefine the interfaces of Dynamoose. I leave this issue open until then.

@hardyscc
Copy link
Owner

hardyscc commented May 4, 2020

Yes eventually all interfaces should be under dynamoose, I will make this happen :)

@hardyscc
Copy link
Owner

hardyscc commented May 4, 2020

@MickL I just released 0.2.0-beta.3 would you mind to have a test. thanks :)

@hardyscc
Copy link
Owner

hardyscc commented May 4, 2020

Could you explain what you mean by broken?

because of

https://github.com/dynamoose/dynamoose/blob/5ae249b680e758bdff9cd29c3fd4d84e0ad5172c/lib/DocumentRetriever.ts#L117

the query cannot be chained like that

  this.model.query('targetId')
  .eq(targetId)
  .exec();

@pfulop
Copy link

pfulop commented May 11, 2020

Hi @hardyscc , I recently did a PR dynamoose/dynamoose#890 that is fixing some of the type definitions in dynamoose. Mick mentioned that this project had some custom interface that eventually should be moved to the dynamoose project and that I should team up with you. What's the strategy here.

@hardyscc
Copy link
Owner

hardyscc commented May 11, 2020

Hi @pfulop, I also facing the same problem, As you know now dynamoose is using a Condition class which shared with scan() and query(), however I cannot find a way to type it correctly when do a query chain like this

  this.model.query('targetId')
  .eq(targetId)
  .exec();

Therefore I just create a type file to overcome it in this project. please see
https://github.com/hardyscc/nestjs-dynamoose/blob/master/lib/interfaces/model.interface.ts

@pfulop
Copy link

pfulop commented May 11, 2020

So just to double-check, the issue is that exec in dynamoose doesn't exist on Condition.

image

So you created ScanInterface and QueryInterface just to be able to call exec on the last condition. If that's the case I can fix it today.

@hardyscc
Copy link
Owner

@pfulop yes correct :)

@pfulop
Copy link

pfulop commented May 11, 2020

@hardyscc please see actual changes here dynamoose/dynamoose@92d1c20

I took some liberties and removed one of the TODOs concerning duplicity.

So with code such as this:

 const queryResult = Stat.query('targetId').eq('targetId').exec();
 const scanREsult = Stat.scan('targetId').eq('targetId').exec();`
 the infered types are
const queryResult: Promise<QueryResponse<dynamoose.Document[]>>
const scanREsult: Promise<ScanResponse<dynamoose.Document[]>>

I also think I can get more granular and work it in a way where the exec result won't be a generic document but rather a document for a specific model. But first I wanted to make sure that you're ok with the changes.

@hardyscc
Copy link
Owner

hardyscc commented May 11, 2020

@pfulop Yes this is definitely the right direction, thanks for your great help!

Furthermore is it possible to support additional generic type for model's key like this?

export interface UserKey {
  id: string;
}

export interface User extends UserKey {
  name: string;
  email?: string;
}

@Injectable()
export class UserService {
  constructor(
    @InjectModel('User')
    private userModel: Model<User, UserKey>,
  ) {}

  update(key: UserKey, user: Partial<User>) {
    return this.userModel.update(key, user);
  }
}

@pfulop
Copy link

pfulop commented May 11, 2020

I think this shall do

dynamoose/dynamoose@a94b1a8

@hardyscc
Copy link
Owner

hardyscc commented May 12, 2020

@pfulop that is wonderful! I am looking forward for this PR. ^^

@hardyscc
Copy link
Owner

hardyscc commented Jan 3, 2021

Just remind myself here, still cannot close this issue yet, need generic type support for Key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wait for others Wait for others
Projects
None yet
Development

No branches or pull requests

3 participants