Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5040

Add color to BSON inspect functions

    • 5
    • 3
    • Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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

        1. bson_colors_dark.png
          287 kB
          Neal Beeken
        2. bson_colors_light.png
          225 kB
          Neal Beeken

            Assignee:
            aditi.khare@mongodb.com Aditi Khare
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Warren James
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: