Skip to content

Conversation

@yoonhoGo
Copy link

No description provided.

@lorensr
Copy link
Member

lorensr commented Dec 26, 2019

Thanks! Wondering how to test this (eg w/ VSCode) and publish to npm?


interface Options { ttl: number }

export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource {
export abstract class MongoDataSource<T extends mongoose.Document, TContext = any> extends DataSource<TContext> {

DataSource is also a generic type, which optionally takes in the context type, which is what we should do imo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I don't think the collection type makes these typings compatible with the native mongodb connector, which has a generic type for collection

@9at8
Copy link
Collaborator

9at8 commented Dec 28, 2019

@lorensr this explains in depth what to do.

TLDR; Add a "types": "index.d.ts" to package.json before publishing

constructor(collection: mongoose.Collection | mongoose.Model<T>)
public initialize(config: DataSourceConfig<TContext>): void
protected findOneById(id: string, { ttl }?: Options): T | null
protected findManyByIds(ids: string[], { ttl }?: Options): (T| null)[]
Copy link
Collaborator

@9at8 9at8 Dec 28, 2019

Choose a reason for hiding this comment

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

The ids are supposed to be ObjectIds, at least for the native driver. Can you confirm @lorensr ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. And if it comes in as a string argument, I use this function to convert:

image

@gayansanjeewa
Copy link

Hi guys,

Any progress on this feature..? We'd love to use this in one of our projects and for that we need the Typescript support.

Thanks in advance.
Gayan

@lorensr
Copy link
Member

lorensr commented Mar 25, 2020

@gayansanjeewa we're waiting on either @yoonhoGo to make the suggested changes and someone to test it, or for someone to create another PR with the changes

@lorensr
Copy link
Member

lorensr commented Mar 25, 2020

Merged #13, released in 0.2.4

@lorensr lorensr closed this Mar 25, 2020
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