Skip to content

Support all standard schema libraries#299

Merged
juliusmarminge merged 18 commits into
t3-oss:mainfrom
EskiMojo14:standard-schema
Jan 25, 2025
Merged

Support all standard schema libraries#299
juliusmarminge merged 18 commits into
t3-oss:mainfrom
EskiMojo14:standard-schema

Conversation

@EskiMojo14

@EskiMojo14 EskiMojo14 commented Jan 25, 2025

Copy link
Copy Markdown
Contributor

Replaces Zod specific logic and types with Standard Schema, meaning all of these should work.

fixes #6

Breaking changes:

  • replace ZodError in onValidationError with an array of Issues.

The minimum version of Zod has been bumped to 3.24, which is the first version to support Standard Schema. I've also made Zod an optional peer dependency, as it's now only needed for presets.

Once this is released, this package can be added here :)

@vercel

vercel Bot commented Jan 25, 2025

Copy link
Copy Markdown

@EskiMojo14 is attempting to deploy a commit to the t3-oss Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jan 25, 2025

Copy link
Copy Markdown

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

Name Status Preview Comments Updated (UTC)
t3-env ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2025 1:43pm
t3-env-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2025 1:43pm

@juliusmarminge

Copy link
Copy Markdown
Member

I've also made Zod an optional peer dependency, as it's now only needed for presets.

I wonder if we should rename the presets entrypoint to preset-zod or something so that there can be preset-valibot etc too

@EskiMojo14

Copy link
Copy Markdown
Contributor Author

sure, that'd make sense - you could maybe export interfaces from /presets that /presets-zod has to satisfy, to make sure they're all matching

it'd be a breaking change but we've already got one of those anyway

@EskiMojo14

Copy link
Copy Markdown
Contributor Author

happy to make that change in this or a follow up PR if you want :)

@juliusmarminge juliusmarminge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work 🔥

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice with another example since we already have astro - but i don't really mind

};
}

export function parseWithDictionary<TDict extends StandardSchemaDictionary>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice if we'd accept object validators so we wouldn't need this, but it was hell getting good types with ZodObject compared to Record<...> when I initially made this

@EskiMojo14 EskiMojo14 Jan 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternative would be requiring the user to provide the object schema builder as an option, but that seems a little annoying from a user perspective (and I haven't tested to make sure it's possible)

createEnv({
  ...opts,
  buildObjectSchema: z.object
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the raw shape to properly check if an accessed variable is shared

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it should be possible to add (although not sure if StandardSchema has a shape type like Zod has. it was just a pain and i think a Record<string, Validator> has worked fine

@juliusmarminge

juliusmarminge commented Jan 25, 2025

Copy link
Copy Markdown
Member

sure, that'd make sense - you could maybe export interfaces from /presets that /presets-zod has to satisfy, to make sure they're all matching

it'd be a breaking change but we've already got one of those anyway

happy to make that change in this or a follow up PR if you want :)

Yea go ahead! Breaking changes are fine. Either follow up or in this one is fine by me

@juliusmarminge

Copy link
Copy Markdown
Member

Actually I'll merge this now. You can make the preset changes in a follow up.

lmk if you're doing them or not so i know if i should push a release or wait

@juliusmarminge
juliusmarminge added this pull request to the merge queue Jan 25, 2025
@EskiMojo14

Copy link
Copy Markdown
Contributor Author

I'll get them done in the next hour or so, so if you're happy to wait to release I'll give you a shout

@juliusmarminge

Copy link
Copy Markdown
Member

sounds good

@EskiMojo14

Copy link
Copy Markdown
Contributor Author

@juliusmarminge raised #310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support more validation libraries

2 participants