Skip to content
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

[ #55 , Data Validation and Document Types ] #88

Merged
merged 2 commits into from
Dec 12, 2023
Merged

Conversation

mohamedsalem401
Copy link
Contributor

  • Use zod
  • Example "in code" for how to add schema validation to markdowndb

Copy link

changeset-bot bot commented Dec 11, 2023

⚠️ No Changeset found

Latest commit: 8e12c10

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Member

@rufuspollock rufuspollock left a comment

Choose a reason for hiding this comment

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

The writing is excellent @mohamedsalem401 👏. Really clear, well-written example. Super easy to review 🙏👏

🏅

A few suggestions you could use to improve if you want.

examples/document-types/README.md Outdated Show resolved Hide resolved
examples/document-types/README.md Outdated Show resolved Hide resolved
## Define Your Schemas

Create a configuration object and use the Zod library to define your schemas. For more information on defining Zod schemas, visit [Zod Documentation - Basic Usage](https://zod.dev/?id=basic-usage). In this example, we'll begin by creating a schema for a blog post.

Copy link
Member

Choose a reason for hiding this comment

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

I'd first show what the blog post markdown file looks like e.g.

Imagine that you have a folder of blog posts that you want to display.

Each blog post should have a well formatted date so you can show the date and display posts in the right order.

But it's easy to forget that date - or type it wrong. And then your site may crash (or look bad)!

How can we ensure each post has a good `date` field like this ...

// INSERT minimal example of blog post with date frontmatter e.g.

---
title: ...
date: 2023-12-05
...
---

My awesome post

...


MarkdownDB automatically validates your Markdown content against the defined schemas using Zod. Here's how the validation process works:

- **Schemas Definition:** The `post` schema is defined using Zod's `object` method, specifying the structure of the content.
Copy link
Member

Choose a reason for hiding this comment

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

We're going to need a way to specify which schemas apply to which files ... HOWEVER, we can leave that question to later. This is a great simple example!

Error: Missing 'date' field in 'blog.md' for the 'post' schema.
```

Now you have robust schemas in place, ensuring the integrity of your Markdown content. Feel free to extend and customize the schemas to meet the specific requirements of your project.
Copy link
Member

Choose a reason for hiding this comment

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

Like the tone. 👏

@mohamedsalem401 mohamedsalem401 merged commit 9493f58 into main Dec 12, 2023
2 of 3 checks passed
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.

2 participants