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

Redefine operation aspects as TypeScript interfaces

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Operations Layer
    • Labels:

      Our operations defines a set of aspects that describe some behavior or functionality that is shared, but not via inheritance. With typescript we can take something like this:  

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class FindOp {}
      defineAspects(FindOp, [EXPLAINABLE])
      

      And create this:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       interface Explainable { explainable: boolean; }
       class FindOp implements Explainable { explainable = true }
      

      This is a simple example with just a boolean prop  but the idea is there, then you can have a type guard function

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       function isExplainable(op: any): op is Explainable { return 'explainable' in op }
      

      Which would replace our current hasAspect check, but the benefit is that typescript can provide type completion to the op variable in this case. So for the example of Explainable, there could be a required instance method that builds the explain options / document. 

      As part of this work we should do this for each aspect.

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

              Created:
              Updated: