Conversation

PavelLoparev

Description

This PR introduces method's arguments validation.

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Fixes

#115

This is a naive implementation that can be extended if needed.

How it works:

  1. IsNotEmptyArgument argument decorator "registers" validation in the target object (just an array of strings like <methodName>:<parameterIndex>:<validatorName>)
  2. ValidateArguments method decorator reads all registered validations and executes them.

This scheme with 2 decorators instead of just one argument decorator is only needed because argument level decorator can't access actual argument value (it's weird)

Usage example:

export class MyClass {
    @ValidateArguments
    async myMethod(@IsNotEmptyArgument test: string): Promise<void> {
        ...
    }
}

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

@PavelLoparev