Skip to content

Feature: memoize result of asynchronous schema #923

@GregOnNet

Description

@GregOnNet

Preface - valibot is awesome

Thank you all for developing this library.
It is the most type-safe library, I have ever used.
It comes with great DX & the docs become better and better.

Use Case

Forms:

  • Sometimes we need to validate certain fields asynchronously.
  • It would be nice if the schema could cache certain inputs and the results of the asynchronous validations to not trigger asynchronous operations if not needed.

New action memoize

Wouldn't it be nice if we could memoize the executions inside a schema, where it is needed?
We could provide a synchronous and an asynchronous version...

memoize
memoizeAsync

Example

v.pipeAsync(
  v.string(),
  v.memoizeAsync(
    v.customAsync(input => fetch(`/api/email/${input}`).then(() => /* ... */)), { 
    buffer: 10, // default 1 - tells how many inputs with their respective result are cached
    itemExpiryInMs: 30_000  // default 5_000
  })
)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestpriorityThis has priority

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions