aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.

Home Page:https://www.npmjs.com/package/mongoose-paginate-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update to be compatible with Mongoose 5.11

Figments opened this issue · comments

Is your feature request related to a problem? Please describe.
As of version 5.11, Mongoose now comes with its own typings, but mongoose-paginate-v2 does not make use of these to make the PaginateModel and PaginateResult types available to use.

Describe the solution you'd like
Update to be compatible with the latest version of Mongoose.

Describe alternatives you've considered
Downgrading for now might work, but this is for future-proofing.

@Figments This is for TS right ?

Yes. The @types/mongoose-paginate-v2 package is based on @types/mongoose, which is looking like it won't be updated since mongoose now has typings on its own. Because of that, mongoose-paginate-v2 does not have proper typing integration with the latest mongoose versions.

Sorry I'm not managing the TS version. Let's see if somebody can help.

Is anyone on this ? What are the alternatives currently?

Would you like to integrate the types into this repository ? If yes, I could do a pull request to help you.

@Figments What version did you downgrade to? What changed made it work? Struggling with this issue now.

I added the following typings to my project:

import 'mongoose';

// required as long as typings from mongoose-paginate-v2 package aren't compatible with the latest version of mongoose
declare module 'mongoose' {
    function model<T extends Document>(
        name: string,
        schema?: Schema<any>,
        collection?: string,
        skipInit?: boolean
    ): PaginateModel<T>;
}

Would you like to integrate the types into this repository ? If yes, I could do a pull request to help you.

I would appreciate it.

I would really appreciate to have typings within this project. It is really a pain to use @types. Most projects (like Mongoose) noeadays come with typings.

@ypicard Can you please explain how exactly you archived that? maybe an example or steps? I'm stuck on this and do not wish to downgrade, since mongoose v5.10** doesn't work well with Serverless

Yes, I added those types to my apps:

import 'mongoose';

// required as long as typings from mongoose-paginate-v2 package aren't compatible with the latest version of mongoose
declare module 'mongoose' {
    function model<T extends Document>(
        name: string,
        schema?: Schema<any>,
        collection?: string,
        skipInit?: boolean
    ): PaginateModel<T>;
}

I did not have a chance to take a look to do a PR, not sure I will be able to for now. If someone wants to give it a shot, feel free.

Okay, @ypicard I don't understand how copying the same content from earlier comment is helpful LoL. Thanks though

I ended up creating a global.d.ts at the root of the project and added this https://gist.github.com/CodeDem/4137a8c64b8543cf5fe702e7194d0401

wherever you need access to types you can use it like this

import { PaginateModel, PaginateOptions } from 'mongoose';

I'm not sure if this approach is good but it works pretty well, let me know your thoughts

I'm sorry I forgot I had already put this before... Not sure I really understand your question then.

I added my code snippet to the types/mongoose.d.ts folder in my project.

Does that answer your question?

@ypicard haha don't say sorry man, your code snippet is actually what I used in the solution I pasted above. Thank you for it :)

Could someone either update the existing typings OR (better) create a PR to add typings to this project? We have so many upvotes already, everyone facing this problem using paginate in TypeScript.

@aravindnc As you are the author of this project you may be super quick creating typings compared to anyone that doesnt know the project as well?

@MickL I understand your point, but sorry I'm not proficient in TS. Would be good if someone can help to update the TS version.

Hi, it's me again.

The work needed to make this library Typescript compatible does not look like being too complicated - most of it being in the ts-version branch.

If setup correctly, I do not see why adding Typescript support would prevent you from being able to provide updates to this library. Typescript is supposed to help you instead of working against you.
Also, this might help other contributors (potentially me) join the project by providing additional guidelines and safety nets.

My question is:
What would it take to actually migrate this project to Typescript? Financial support? Additional contributors? Support for the initial migration? It would be great to understand this better so that we can actually move forward together on this issue.

@ypicard I would really appreciate some contributors to step in for updating the ts version.

What process would you like to setup then? Someone comes up with a PR replacing the existing js implementation with a fully TS one? I could take care of this.

@ypicard For now lets update this one https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mongoose-paginate-v2

Later, I will replace the current library with ts version.

The types should be going in the library's source code directly. Is this part of your plan?

@ypicard Yes I will replace existing implementation with ts version soon.

@aravindnc Let me know if this works for you and I will mark the PR as Ready for review: DefinitelyTyped/DefinitelyTyped#58304

@ypicard Awesome. Let me take a look.

Hi @aravindnc , any comments on the PR?

@ypicard Sorry for the delay. Just checked the code and I can see that the update was only for adding parameter parameter class. Not sure if I'm looking at the wrong PR. Shouldn't there be complete ts transformed code for the whole plugin. Let me know if I'm wrong.

DefinitelyTyped/DefinitelyTyped#58304

@ypicard Yes I will replace existing implementation with ts version soon.

Perhaps I misunderstood this comment then.

I thought you were planning on migrating to Typescript on your end soon - and that DefinitelyTyped typings should be updated in the meantime. Correct?

@ypicard Oops! Sorry if I'm not being clear.

What I meant was that once you update the DefinitelyTyped typings with ts version, I will move your TS code to current plugin library down the track. Since I'm not that much into TypeScript, I'm having hard time to do the ts conversion. So if I switch the library entirely to TS version now then it must be hard for me to do further updates. So I'm planning to keep the JS and TS version separate for the time being and will merge it in the future.

I think there is a misunderstanding here. Let me know if the following makes sense to you:

  • The DefinitelyTyped project is a project aiming to contain only typing definitions for a project that does not support typescript itself. It is not meant to contain the equivalent package code written in typescript - which I think is what you were expecting to see in the above PR.
  • The PR I put up is to synchronize the typings available in the DefinitelyTyped project with the raw javascript code available in this package. It is supposed to reflect the different entities' interfaces only - not their actual code - so that when people install your javascript package in their typescript project, they can still have access to the equivalent typings.

What I think we are trying to do here is the following:

  1. update the current typings in the DefinitelyTyped project to reflect the current interfaces made available by this project. They are currently out of sync: this is why I am adding only the interface of the PaginationParameters class in my PR.
  2. instead of having the typings for this project live in DefinitelyTyped, it would be more convenient to have them referenced in this repository directly. This prevents people from needing to install 2 different packages to use this library (this one and the DefinitelyTyped definitions). This can be done without migrating the existing codebase to Typescript.
  3. actually migrate the codebase to Typescript
  4. remove the typings defined in step 2 as they will now be automatically generated by the Typescript code base introduced in step 3

Let me know if you would like to proceed this way and I will send the PR for review.

@ypicard Thanks for explaining. I would prefer option 2 for the time being.

PR is up.

@ypicard Version updated. Can you take a look.

LGTM. Thanks for helping in this @aravindnc.