From 1d3fe1134730cf7c306703c9b7e6374905750d71 Mon Sep 17 00:00:00 2001 From: Matthew Hendricks Date: Thu, 11 Sep 2025 15:02:59 -0700 Subject: [PATCH] docs: rewrite getting started guide --- MIGRATION.md | 2 ++ README.md | 2 ++ docs/getting-started.md | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/MIGRATION.md b/MIGRATION.md index 8ee98cd..639bc27 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -53,6 +53,8 @@ fieldtest/ ```typescript import { validateWithSchema, marketingCopySchema } from '@watthem/fieldtest'; ``` +See [docs/getting-started.md](./docs/getting-started.md) for a guided Standard Schema example. + ### For Markdown Processing diff --git a/README.md b/README.md index e234904..d5b9672 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ npx turbo build pnpm test ``` +For a step-by-step Standard Schema walkthrough, see [docs/getting-started.md](./docs/getting-started.md). + ## Package `@watthem/fieldtest` bundles the core validation engine, schema registry, and framework integrations into a single, cohesive package: diff --git a/docs/getting-started.md b/docs/getting-started.md index e69de29..d52e218 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -0,0 +1,66 @@ +# Getting Started + +Follow these steps to validate content with FieldTest's Standard Schema. + +## 1. Install + +```bash +pnpm add @watthem/fieldtest +``` + +## 2. Define a schema + +```ts +import type { StandardSchemaV1 } from '@watthem/fieldtest'; + +export const blogPostSchema: StandardSchemaV1 = { + version: '1', + name: 'blog-post', + fields: { + title: { type: 'string', required: true }, + published: { type: 'boolean', required: true }, + content: { type: 'string', required: true }, + tags: { type: 'string', array: true } + } +}; +``` + +## 3. Load and validate + +```ts +import { loadUserSchema, validateWithSchema } from '@watthem/fieldtest'; +import { blogPostSchema } from './schema'; + +const schema = loadUserSchema(blogPostSchema); + +const doc = ` +--- +title: "Hello" +published: true +--- +Content here +`; + +const result = validateWithSchema(doc, schema); + +if (result.valid) { + console.log('ok'); +} else { + console.error(result.errors); +} +``` + +### No extra helpers + +- `loadUserSchema` and `validateWithSchema` handle schema setup and validation. +- Tools like `zodToStandardSchema`, custom schema loaders, or manual validation pipelines are no longer necessary. + +### Native replacements for removed helpers + +These APIs replace earlier utilities that shipped with FieldTest: + +- `loadUserSchema` replaces bespoke schema loading helpers. +- `validateWithSchema` replaces manual validation functions. + +Using them keeps your code minimal and consistent across frameworks. +