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

Improve parseIndexOptions helper function

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • 3
    • Not Needed

      How are you using Mongo? What version of the server and driver are you using?

      I develop the driver

      What is the feature/improvement you would like?

      The `parseIndexOptions` has a significant amount of tech debt requiring lots of `any` usage and doesn't have effective narrowing of the various indexSpec shapes possible (e.g, tuple, array of tuples, etc.). It also collects an unused keys property.

      What use case would this feature/improvement enable?

      It's a quick to clean up and help the next person understand what it is trying to do. It's also missing support for top-level tuple arguments: index(['name', 1])

      AC

      • Remove the array types from IndexSpecification, OneOrMore already provides array of tuples and array of objects (mappings)
      • Refactor forEach to for loop, narrow the types to the three (6) possible cases
        • string, tuple, mapping (and then each of those can be passed in as an array)
        • consider wrapping the input in an array to make the remainder of the function streamlined, watch out for tuple case
        • remove duplicate type handling for index spec shape
      • fieldHash continues to track the key to direction mapping.
      • Add unit tests for parseIndexOptions

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: