question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asynchronous validations

See original GitHub issue

There’s support for validating promise types, but I don’t see a way to create async validators.

What I’m thinking of is something like this:

const foreignKey = z.string().refine(idExistsAsync, {
  message: "ID not found",
});
foreignKey.parseAsync("1234")

Where idExistsAsync is some function that asynchronously checks some backend to make sure that the value is valid. It returns a promise. Of course this would mean that the entire schema becomes async, so there are some other concerns here when async values are used as fields on objects.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
colinhackscommented, Sep 17, 2020

This is now available in the Zod 2 beta: https://github.com/vriad/zod/tree/v2

@chrbala @Albertbol

1reaction
Albertbolcommented, Sep 17, 2020

Thank you that’s awesome ! Will test it out

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous Validation — FluentValidation documentation
By default, FluentValidation allows custom rules defined with MustAsync or CustomAsync to be run asynchronously, as well as defining asynchronous conditions ...
Read more >
Asynchronous validation - Ajv JSON schema validator
Asynchronous validation. You can define formats and keywords that perform validation asynchronously by accessing database or some other service.
Read more >
Using Custom Async Validators in Angular Reactive Forms
In Angular, you can do this using Async Validators. Create a basic application. We are going to create a very minimalist form that...
Read more >
yiminghe/async-validator: validate form asynchronous - GitHub
If your validation involves multiple asynchronous calls (for example, database queries) and you only need the first error use this option.
Read more >
Async Validation In Angular - C# Corner
Rules for Async Validator · The function must implement the AsyncValidatorFn Interface, which defines the signature of the validator function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found