-
Type: New Feature
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: BSON
Use case
When printing out BSON values in Node.js they appear all one color. Node.js colors the various types of javascript values and we can harness that for BSON types.
POC: https://github.com/mongodb/js-bson/compare/main...feat/add-color
User Impact
- BSON types will now print out in color in Node.js
- No impact on web users, .inspect() should work the same
Dependencies
- None
Unknowns
- Q: What is a reasonable quick web-compatible stringifier function?
- possibly just JSON stringify with a replacer for bigint?
- What about NaN, Map, or other non-JSON representable values?
- EJSON?
- A: if inspect APIs aren't available fallback to existing behavior
Acceptance Criteria
Mini Design
- In kickoff dedicate a section to the precise format for each BSON type
- The screenshots show some adjustments to the current formatting, some are necessary (code w/ scope, dbref) some are a preference (Long's with bigint). We want to run any changes by shell.
Implementation Requirements
- Node.js' custom inspect function already receives a depth number, options object and inspect function as arguments, add bindings for these arguments.
- [Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect)
- Pass these arguments through to .inspect methods on each BSON type
- .inspect() is public API that MUST still be callable with no arguments. Add default values for each parameter.
- The default function for inspect should fallback to the current implementation
- See answer to unknown
- Update template strings to stringify the JavaScript values representing a BSON type using the passes in the inspect function.
- ex. `new Int32(${this.value})` -> `new Int32(${inspect(this.value)})`
- Ensure inspect is invoked with the depth and option values
Testing Requirements
- Make sure the tests that eval the strings produced by inspect are still passing and accurate
- Unit test color is produced when enabled (confidence check)
- Test nested documents in Code and DbRef print correctly
- Test w/ bigint values
Documentation Requirements
- Release notes with HD Full color screen shots!!
Follow Up Requirements
- None
- depends on
-
NODE-4855 Add static fromX bson type creation methods to Binary and ObjectId
- Closed
- has to be finished together with
-
NODE-5157 Using bigint in Code's scope throws when inspected
- Closed
- is depended on by
-
COMPASS-7131 Investigate changes in NODE-5040: Add color to BSON inspect functions
- Closed