contentlayerdev / contentlayer

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://www.contentlayer.dev
MIT License
3.29k stars 202 forks source link

Runtime config / schema validation #214

Open schickling opened 2 years ago

schickling commented 2 years ago

Some users (typically users who don't yet use TypeScript) are running into problems due to misconfigurations of their Contentlayer config (especially in regards to the content schema). Additionally to the safety provided by TypeScript, we should also implement a runtime validation step to avoid undefined runtime errors.

Technical notes

Ideally we should figure out a way how to derive Zod-like validation logic based on the existing TypeScript definitions. We could also investigate to use TS+ for this.

Related issues

ivan-kleshnin commented 2 years ago

You're likely talking about a different layer here, just FYI. As a contentlayer user I would certainly prefer well-known and tested zod schemas over custom type definitions within defineDocumentType: https://www.contentlayer.dev/docs/reference/source-files/field-types -1 DSL to learn is a big deal.

airtonix commented 1 year ago

+1 if you could generate zod schemas then we can just infer types from that and we'd also be able to insert the schemas in the .input and .output of trpc routers:

lucgagan commented 1 year ago

+1 for zod