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

Any way to support multi ? #38

Closed
thib3113 opened this issue Jan 6, 2024 · 6 comments
Closed

Any way to support multi ? #38

thib3113 opened this issue Jan 6, 2024 · 6 comments

Comments

@thib3113
Copy link

thib3113 commented Jan 6, 2024

Hello, is there a way to use multi from fastest-validator ? (search return nothing, so I think no) .

@AmauryD
Copy link
Owner

AmauryD commented Feb 12, 2024

Hello, sorry for the late response.
There's no decorator Multi at the moment. But you could implement Multi using the @field decorator.

@Schema({ strict: true })
class Test {
        @Field({ 
        type: "multi", 
        rules: [
          { type: "boolean" },
          { type: "number" }
        ], default: true 
      })
      public prop!: boolean | number;
}

@thib3113
Copy link
Author

Oh great ! I miss Field wich can in fact allow all types ... interesting . I will try :)

@AmauryD
Copy link
Owner

AmauryD commented Feb 12, 2024

I will soon add the @multi decorator, which can be used in two ways:

  @Schema({
    async: true,
  })
  class Test {
    @String()
    @Number()
    @Boolean()
      name!: string | number | boolean;
  }

and

  @Schema({
    async: true,
  })
  class Test {
    @Multi({
      rules: [
        { type: "string" },
        { type: "number" },
        { type: "boolean" },
      ],
    })
      name!: string | number | boolean;
  }

Bot translate to a multi property.

{
        "$$async": true,
        "$$strict": false,
        "name": {
          "rules": [
            {
              "type": "string",
            },
            {
              "type": "number",
            },
            {
              "type": "boolean",
            },
          ],
          "type": "multi",
        },
      }

@thib3113
Copy link
Author

@AmauryD great ! I will wait for the next release :) .

This is totally out of this topic, but, can you open the options in Schema ? ( to allow custom metas ? icebob/fastest-validator#341 ) ( if you work on this project, it's maybe not too much work to add this ? else, I can try to do a PR )

@AmauryD
Copy link
Owner

AmauryD commented Feb 12, 2024

I can allow unknown keys in @Schema decorators. If that's what you mean. The types will follow when your PR is merged upstream.

@thib3113
Copy link
Author

I didn't have another use case with multi at the moment . But field works great, so I will close this issue .

Thank you

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

No branches or pull requests

2 participants