francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

feat: support mongoose-autopopulate #136

Closed horvbalint closed 6 months ago

horvbalint commented 6 months ago

There is a package called mongoose-autopopulate which allows annotating the fields of a schema and then always populates the selected fields. We are using this package and it would be great if mongoose-tsgen would support its annotation, and generate typescript definitions accordingly.

In this PR I made a small change that does work for type definition generation, but I am not sure if this is good enough, or something else needs to be done as well.

Additionally, mongoose-autopopulate has some configs, like a per-field maxDepth options (eg.: {maxDepth: 2}), which limits the population depth. Im not sure if this is even possible, but it would be even better if mongoose-tsgen could generate type definitions with fields that are populated until some depth :D

francescov1 commented 6 months ago

Great idea, thanks for the PR! Do you mind adding a test for it? Theres already a test suite for getParseKeyFn, just mimic what's already there

horvbalint commented 6 months ago

Of course, I added test cases for normal references and with autopopulate: false and autopopulate: true :)

francescov1 commented 6 months ago

Update is live in v9.2.11 🚀 thanks again!