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

feat(NODE-3115): Add generic parameterization #2767

Merged
merged 16 commits into from
May 14, 2021
Merged

Conversation

nbbeeken
Copy link
Contributor

Add Generics to Typescript Code

Building upon the splendiferous efforts in the community typings, I've brought inhouse the functionality to create collections across a typescript type. Please see the comments I'll post in short order for implementation details.

It's worth calling out: This does not enable runtime type checking, or BSON to class mapping.

NODE-3115

package.json Outdated Show resolved Hide resolved
src/bson.ts Show resolved Hide resolved
src/change_stream.ts Outdated Show resolved Hide resolved
src/change_stream.ts Show resolved Hide resolved
src/gridfs-stream/index.ts Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
test/unit/type_check.test.ts Outdated Show resolved Hide resolved
test/unit/types/basic_schema.test-d.ts Outdated Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
CONTRIBUTORS.md Show resolved Hide resolved
@nbbeeken nbbeeken requested review from emadum and durran March 26, 2021 15:14
@nbbeeken nbbeeken marked this pull request as ready for review March 26, 2021 15:14
src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

MongoClient, Db, Collection, and Cursors can now accept generic
parameters to type check the usage of the various API methods on each
class. Using generics is kept optional.
src/bulk/common.ts Outdated Show resolved Hide resolved
src/cursor/abstract_cursor.ts Outdated Show resolved Hide resolved
src/cursor/abstract_cursor.ts Outdated Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
src/mongo_types.ts Outdated Show resolved Hide resolved
test/types/mongodb.test-d.ts Show resolved Hide resolved
test/types/union_schema.test-d.ts Outdated Show resolved Hide resolved
test/types/indexed_schema.test-d.ts Show resolved Hide resolved
src/collection.ts Outdated Show resolved Hide resolved
test/types/basic_schema.test-d.ts Outdated Show resolved Hide resolved
src/bulk/common.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

A few things left to clean up - almost there!

const stream = changeStream[kCursorStream] || cursor.stream();
changeStream[kCursorStream] = stream;
stream.on('data', change => processNewChange(changeStream, change));
stream.on('error', error => processError(changeStream, error));
}

function endStream(changeStream: ChangeStream): void {
function endStream(changeStream: ChangeStream<any>): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this one also be typed or is it an intentional omission?

src/change_stream.ts Outdated Show resolved Hide resolved
test/types/schema_helpers.test-d.ts Outdated Show resolved Hide resolved
test/types/schema_helpers.test-d.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken requested a review from dariakp May 14, 2021 21:22
Copy link
Contributor

@dariakp dariakp left a comment

Choose a reason for hiding this comment

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

🚀

@nbbeeken nbbeeken merged commit 4d12491 into 4.0 May 14, 2021
@nbbeeken nbbeeken deleted the NODE-3115/ts-generics branch May 14, 2021 21:36
ljhaywar pushed a commit that referenced this pull request Nov 9, 2021
MongoClient, Db, Collection, and Cursors can now accept generic
parameters to type check the usage of the various API methods on each
class. Using generics is kept optional.
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.

5 participants