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

fix(NODE-3275): Fix enum type export naming and serverApi validation #2809

Merged
merged 4 commits into from
May 18, 2021

Conversation

dariakp
Copy link
Contributor

@dariakp dariakp commented May 14, 2021

Description

NODE-3275

Make type exports for enums use the same name as the enums themselves


/** @public */
export interface ServerApi {
version: string | ServerApiVersionId;
version: string | ServerApiVersion;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@emadum Do you happen to know why this is typed as string | ServerApiVersion? The api version is also a string, so this typing is equivalent to just string - do we actually want to allow arbitrary strings here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall a reason, we don't want to allow arbitrary strings so I think string can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it looks like it's currently assigned when we parse the connection options on the condition that it is a string... do we want to restrict the option validation so that only the api versions known to the driver are supported? or do we want users to be able to specify any version regardless of whether it's known to the driver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cross referencing the spec:
it looks like the string | ServerApiVersion given in the spec for the class is intended to accommodate languages that can't provide an enum; since we can provide an enum via typescript, it's fine for us to just have the enum, however in light of:

the driver MUST validate (e.g. when the application provides a version string to the ServerApi class) that the version string is valid and trigger a client-side error if an unknown API version was used

I'm going to add the check and error in the connection parser since typescript doesn't provide run time validation

@dariakp dariakp force-pushed the NODE-3275/enum-type-export-naming branch from b6f2fb8 to f420e36 Compare May 17, 2021 19:48
@dariakp dariakp marked this pull request as ready for review May 17, 2021 21:17
@dariakp dariakp requested review from a team, durran, emadum and nbbeeken and removed request for a team May 17, 2021 21:17
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

A suggestion, we can discuss:

src/connection_string.ts Outdated Show resolved Hide resolved
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

Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

Nice error message change! 👍

@dariakp dariakp changed the title refactor(NODE-3275): Update enum type export naming fix(NODE-3275): Fix enum type export naming and serverApi validation May 18, 2021
@dariakp dariakp merged commit 661511d into 4.0 May 18, 2021
@dariakp dariakp deleted the NODE-3275/enum-type-export-naming branch May 18, 2021 21:35
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.

3 participants