Skip to content

feat: Add Standard Schema interface #965

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

Draft
wants to merge 9 commits into
base: next
Choose a base branch
from
Draft

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Apr 6, 2025

This adds a new export, createStandardSchemaV1, which (as the name implies), creates a standard-schema compatible object that can be fed to tRPC's inputs, or TanStack Router for search params validation.

image

Since nuqs parsers always assume they have to deal with deserialisation, and those validation libraries generally assume they work with data already of the right shape (kind of) and verify runtime constraints, we first run the input through the serializer to generate a URL, which we can then parse.

This also introduces a new option on the loaders: strict mode, which will throw errors rather than applying default values (or returning null) for invalid querystring values.

It also fixes a bug where the loader functions had a signature mismatching the runtime implementation: passing urlKeys is only supported when creating the loader function, which now can accept a different set of runtime options like strict mode. We're renaming the types to make this clearer.

It also deprecates parseServerSide for parsers, as it was an internal artefact of resolving a non-nullable type when specifying a default value. Loaders now have integrated parseServerSide's duties and do provide stronger key/value type-safety (while also supporting other things like strict mode and urlKeys).

Tasks

  • Add tests
  • Add example with tRPC
  • Add docs
  • Test equality of input/output in the SSv1 validate method ?

@franky47 franky47 added the feature New feature or request label Apr 6, 2025
@franky47 franky47 added this to the 🪵 Backlog milestone Apr 6, 2025
Copy link

vercel bot commented Apr 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 0:29am

Copy link

pkg-pr-new bot commented Apr 6, 2025

pnpm add https://pkg.pr.new/nuqs@965

commit: ada6de0

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

Successfully merging this pull request may close these issues.

1 participant