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

Are there any similarities about zod .superRefine? #546

Closed
dhythm opened this issue Apr 24, 2024 · 2 comments
Closed

Are there any similarities about zod .superRefine? #546

dhythm opened this issue Apr 24, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@dhythm
Copy link

dhythm commented Apr 24, 2024

Hi, folks!
I'm just considering to migrate validator from zod to valibot.
Then, I met an issue to prevent it.

zod provides superRefine method and it is useful like the following case;

somethingSchema.superRefine((val, ctx) => {
  if (!val.length) {
    ctx.addIssue({
     code: z.ZodIssueCode.custom
      message: "not inputted"
    })
  }
  const overLength = val.length - MAX_LENGTH
  if (overLength > 0) {
    ctx.addIssue({
     code: z.ZodIssueCode.custom
      message: `${overLength} characters exceeded from max length`
    })
  }
})

I guess pipeline with custom cannot cover this use case;

  string([
    custom(input => !!input.length, "not inputted"),
    custom(input => input.length - MAX_LENGTH <= 0, `${input.length - MAX_LENGTH} characters exceeded from max length`) // cannot get `input.length`
  ])

Are there any solution about this in valibot?

@fabian-hiller
Copy link
Owner

We are currently rewriting Valibot. This will most likely be possible in the future. I expect a new release in about 3 or 4 weeks. You can follow the progress in #502.

@fabian-hiller fabian-hiller self-assigned this Apr 25, 2024
@fabian-hiller fabian-hiller added enhancement New feature or request question Further information is requested labels Apr 25, 2024
@fabian-hiller
Copy link
Owner

We now support rawCheck and rawTransform. Both APIs are similar to superRefine in Zod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants