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-5040): add color to BSON inspect #635

Merged
merged 17 commits into from
Oct 16, 2023

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented Oct 6, 2023

Description

Utilizing Node.js's custom inspect functionality [Symbol.for('nodejs.util.inspect.custom')], we are able to write custom functions to print out user input to BSON types. This allows users to visualize their BSON objects in color, as well as set options to their inspect function.

What is changing?

Node.js colors the various types of javascript values, through the inspect function, and we can now harness that for BSON types. In addition, we support all user-defined inspect option inputs, for all types except RegExp.

This functionality is not available in the browser, in which case the Node Driver defaults to the default JS inspect.

Is there new documentation needed for these changes?

Yes. Users need to be provided with information about what is printed with the new inspect functionality and how to modify the options.

What is the motivation for this change?

To help users have better control over their visualization of BSON objects, especially in the case of color visualization of values of different types.

Release Highlight

Node.js BSON now supports inspect options, specifically visualizing in color

Prior Visualization:

Pre-Color BSON Objects

New Color Visualization:

Post Color BSON Objects

Other Notable Changes

  • Strings have consistent single quotes around them, other than the case of a code block that has a string within
  • Code blocks with newlines will be visually printed with newlines for easier reading

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@aditi-khare-mongoDB aditi-khare-mongoDB marked this pull request as ready for review October 6, 2023 19:48
src/binary.ts Outdated Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
src/db_ref.ts Show resolved Hide resolved
@nbbeeken nbbeeken changed the title feat(Node 5040): add color to BSON inspect feat(NODE-5040): add color to BSON inspect Oct 9, 2023
@W-A-James W-A-James self-assigned this Oct 9, 2023
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 9, 2023
Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

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

Looks good, but I agree with Anna's comments.

src/binary.ts Outdated Show resolved Hide resolved
src/db_ref.ts Outdated Show resolved Hide resolved
src/db_ref.ts Outdated Show resolved Hide resolved
src/bson_value.ts Show resolved Hide resolved
src/regexp.ts Outdated Show resolved Hide resolved
test/node/bson_test.js Outdated Show resolved Hide resolved
test/node/bson_test.js Outdated Show resolved Hide resolved
test/node/bson_test.js Outdated Show resolved Hide resolved
test/node/bson_test.js Outdated Show resolved Hide resolved
test/node/bson_test.js Outdated Show resolved Hide resolved
test/colors.mjs Outdated Show resolved Hide resolved
src/symbol.ts Outdated Show resolved Hide resolved
src/bson_value.ts Outdated Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
test/colors.mjs Outdated Show resolved Hide resolved
W-A-James
W-A-James previously approved these changes Oct 12, 2023
@W-A-James W-A-James added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Oct 12, 2023
baileympearson
baileympearson previously approved these changes Oct 12, 2023
@nbbeeken nbbeeken self-requested a review October 12, 2023 15:03
src/double.ts Outdated Show resolved Hide resolved
src/regexp.ts Outdated Show resolved Hide resolved
src/timestamp.ts Outdated Show resolved Hide resolved
test/node/binary.test.ts Outdated Show resolved Hide resolved
src/regexp.ts Outdated Show resolved Hide resolved
src/bson_value.ts Show resolved Hide resolved
src/parser/utils.ts Outdated Show resolved Hide resolved
nbbeeken
nbbeeken previously approved these changes Oct 13, 2023
Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

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

LGTM, but not sure why we brought back test/colors.mjs

test/colors.mjs Outdated Show resolved Hide resolved
@W-A-James W-A-James merged commit 7802c66 into main Oct 16, 2023
4 checks passed
@W-A-James W-A-James deleted the NODE-5040/add-color-to-BSON-inspect branch October 16, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants