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

Custom validators #792

Closed
SupremeTechnopriest opened this issue Aug 29, 2023 · 9 comments
Closed

Custom validators #792

SupremeTechnopriest opened this issue Aug 29, 2023 · 9 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects

Comments

@SupremeTechnopriest
Copy link

Hello!

Has the ability to create custom comment tags been removed from v5? It looks like the customValidators.insert function is no longer exported. I see the documentation for creating custom validation types, but I prefer the comment tag syntax.

@samchon
Copy link
Owner

samchon commented Aug 30, 2023

Yes, removed it for type safety.

@samchon samchon self-assigned this Aug 30, 2023
@samchon samchon added the question Further information is requested label Aug 30, 2023
@SupremeTechnopriest
Copy link
Author

SupremeTechnopriest commented Aug 30, 2023

Okay, so no way to do custom comment tags anymore? The new API makes it difficult to do complicated validations because everything is a string now.

For example:

export type CommaSeparated<Value extends string> = tags.TagBase<{
  kind: 'commaSeparated',
  target: 'string',
  value: Value,
  validate: `$input.split(',').every(v => ${Value}.split(',').includes(v))`
}>

This validator fails to compile. I want to validate if a comma separated string of values is part of a union type. Is there a better way to achieve this? Im validating a search parameter so passing an array isn't possible.

@SupremeTechnopriest
Copy link
Author

Trying to use it like this:

interface IRequestQuery {
  foo: string & CommaSeparated<'bar,baz'>
}

@SupremeTechnopriest
Copy link
Author

SupremeTechnopriest commented Aug 30, 2023

Ideally I would be able to use an actual union type:

export type MyType = 'bar' | 'baz'

@SupremeTechnopriest
Copy link
Author

Any suggestions on how to implement this validator? It seems to fail when I pass the iterator function to every.

@samchon samchon added bug Something isn't working enhancement New feature or request good first issue Good for newcomers and removed question Further information is requested labels Aug 31, 2023
@samchon samchon added this to To do in V5 Update via automation Aug 31, 2023
@samchon
Copy link
Owner

samchon commented Aug 31, 2023

Succeeded to find the reason why bug being occured.

Would be fixed soon, and patch version 5.0.1 would be published soon.

Thanks for reporting.

@SupremeTechnopriest
Copy link
Author

Awesome! Glad to help!

samchon added a commit that referenced this issue Aug 31, 2023
Fix #792 - custom type tag when callback function being used.
V5 Update automation moved this from To do to Done Aug 31, 2023
@SupremeTechnopriest
Copy link
Author

Works like a charm. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
No open projects
Development

No branches or pull requests

2 participants