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
@nbbeeken nbbeeken force-pushed the NODE-3115/ts-generics branch from 271ce21 to 16f0df0 Compare April 8, 2021 19:18
src/index.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken requested review from durran and dariakp April 20, 2021 17:56
@nbbeeken nbbeeken force-pushed the NODE-3115/ts-generics branch from 98135ef to b7fce6b Compare April 21, 2021 18:29
@nbbeeken nbbeeken force-pushed the NODE-3115/ts-generics branch from b7fce6b to 1de5be6 Compare May 6, 2021 17:15
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! 🚀

nbbeeken added 6 commits May 10, 2021 14:42
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.
@nbbeeken nbbeeken force-pushed the NODE-3115/ts-generics branch from 1de5be6 to 2136bdf Compare May 10, 2021 18:45
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