Skip to content

Conversation

@sdorra
Copy link
Owner

@sdorra sdorra commented May 13, 2025

Use every StandardSchema compliant library for validation.

To use StandardSchema for validation just use the library of your choice:

zod:

import { defineCollection, defineConfig } from "@content-collections/core";
import { z } from "zod";

const posts = defineCollection({
  name: "posts",
  typeName: "Post",
  schema: z.object({
    title: z.string().min(5),
    description: z.string().min(10),
    date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
  }),
  directory: "sources/posts",
  include: "**/*.md(x)?",
});

export default defineConfig({
  collections: [posts],
});

valibot:

import { defineCollection, defineConfig } from "@content-collections/core";
import * as v from "valibot";

const posts = defineCollection({
  name: "posts",
  typeName: "Post",
  schema: v.object({
    title: v.pipe(v.string(), v.minLength(5)),
    description: v.pipe(v.string(), v.minLength(10)),
    date: v.pipe(v.string(), v.regex(/^\d{4}-\d{2}-\d{2}$/)),
  }),
  directory: "sources/posts",
  include: "**/*.md(x)?",
});

export default defineConfig({
  collections: [posts],
});

The old syntax will still work, but it will log a deprecation message. Unfortunately, it seems impossible to mark the usage of the old syntax as deprecated. Marking the part of the union type as deprecated does not affect the usage itself.

In future versions, possibly 1.0.0, we will remove the old syntax and the dependency on Zod.

Todos

  • Log deprecation message
  • Update documentation
  • Add a sample with Valibot
  • Add a sample with ArkType
  • Changelog entry
  • Use new syntax on the website
  • Use new syntax for samples
  • API to suppress deprecation warning
  • Update landing page (section: Powerful Validation)
  • Update installer
  • Talk to @fuma-nama about fumadocs integration

Closes: #528

@changeset-bot
Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 0495fe4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@content-collections/core Minor
content-collections Minor
@content-collections/installer Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented May 13, 2025

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

Name Status Preview Comments Updated (UTC)
content-collections ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 6:29am

@sdorra sdorra self-assigned this May 13, 2025
@sdorra sdorra added the enhancement New feature or request label May 13, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented May 13, 2025

Open in StackBlitz

@content-collections/cli

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/cli@570

content-collections

npm i https://pkg.pr.new/sdorra/content-collections@570

@content-collections/installer

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/installer@570

@content-collections/core

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/core@570

@content-collections/integrations

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/integrations@570

@content-collections/markdown

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/markdown@570

@content-collections/mdx

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/mdx@570

@content-collections/next

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/next@570

@content-collections/remix-vite

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/remix-vite@570

@content-collections/vinxi

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/vinxi@570

@content-collections/vite

npm i https://pkg.pr.new/sdorra/content-collections/@content-collections/vite@570

commit: 0495fe4

sdorra added 3 commits May 17, 2025 20:50
Explain the use of Standard Schema in the configuration.
Add a page that describes the migration process.
@sdorra sdorra marked this pull request as ready for review May 22, 2025 06:39
@sdorra sdorra added the preview-release Deploy a preview release label May 22, 2025
@sdorra sdorra merged commit 846c36a into main May 26, 2025
10 checks passed
@sdorra sdorra deleted the feature/528_standardschema branch May 26, 2025 11:17
@github-actions github-actions bot mentioned this pull request May 25, 2025
@fabian-hiller
Copy link

Thank you for supporting Standard Schema! 🔥

@ElasticBottle
Copy link

This is awesome, was pleasantly surprise I don't have to install zod just for this!

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

Labels

enhancement New feature or request preview-release Deploy a preview release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Standard Schema

4 participants