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

types: MethodMap and ExecuteMethodMap should understand optional/required parameters #18455

Open
boneskull opened this issue Apr 5, 2023 · 1 comment
Labels
DX developer experience (extension authoring, contributing, etc.) Enhancement feature Help Needed contributions wanted!

Comments

@boneskull
Copy link
Contributor

This should be possible. We can cross-reference the values of the required and optional parameters lists with the parameters on the method implementation to ensure the required params are actually required and the optional ones are not.

e.g.:

const executeMethodMap = {
  '/session/:sessionId/foo': {
    POST: {
      command: 'doFoo',
      payloadParams: {
        required: ['a', 'b'],
        optional: ['c']
      }
    }
  }
} as const satisfies ExecuteMethodMap<MyDriver>;

// elsewhere...

class MyDriver extends BaseDriver<SomeConstraints> {
  static executeMethodMap = executeMethodMap;

  // required params come first, in order
  // then optional params
  async doFoo(a: string, b: string, c?: string) { // not an error
    // stuff
  }
}

// an error would occur if doFoo was:

class {
  async doFoo(a: string, b: string, c: string) { // c should be optional per executeMethodMap
    // stuff
  }
}
@boneskull boneskull added Enhancement feature DX developer experience (extension authoring, contributing, etc.) labels Apr 5, 2023
@boneskull
Copy link
Contributor Author

Note that parameters are handled in order, starting with required parameters, then optional parameters.

@boneskull boneskull added the Help Needed contributions wanted! label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX developer experience (extension authoring, contributing, etc.) Enhancement feature Help Needed contributions wanted!
Projects
None yet
Development

No branches or pull requests

1 participant