Skip to content

watthem/fieldtest

Repository files navigation

FieldTest

A validation toolkit for Markdown and Standard Schema β€” built for Astro, Next.js, and modern frameworks.

npm version License: MIT TypeScript GitHub stars

FieldTest is a framework-agnostic TypeScript validation toolkit that brings order to content chaos. Whether you're building with Astro, Next.js, or any modern framework, FieldTest ensures your markdown content and frontmatter data is consistent, valid, and production-ready.

✨ Why FieldTest?

  • 🚫 No more runtime content errors β€” Catch validation issues at build time
  • πŸ”„ Framework agnostic β€” Works seamlessly with Astro, Next.js, Remix, SvelteKit, and more
  • πŸ“‹ Standard Schema compliant β€” Built on Standard Schema v1 for maximum interoperability
  • ⚑ Performance first β€” <50ms validation per document, handles 5000+ files efficiently
  • πŸ› οΈ Developer friendly β€” Excellent TypeScript support with comprehensive error messages
  • πŸ”§ Zero config β€” Works out of the box, customizable when you need it

Project Structure

fieldtest/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ core/                    # Core markdown processing
β”‚   β”œβ”€β”€ validate/                # Validation utilities
β”‚   β”œβ”€β”€ registry/                # Schema registry
β”‚   β”œβ”€β”€ shared/                  # Common utilities and types
β”‚   β”œβ”€β”€ examples/                # Example implementations
β”‚   └── integrations/
β”‚       └── mcp/
β”‚           └── fieldtest-mcp-server/  # MCP server for AI workflows
β”œβ”€β”€ grit-plugins/                # Biome GritQL linting plugins
β”œβ”€β”€ docs/                        # Documentation
β”‚   β”œβ”€β”€ guides/                  # How-to guides
β”‚   β”œβ”€β”€ reference/               # API reference
β”‚   └── explainers/              # Conceptual articles
β”œβ”€β”€ scripts/                     # Build and utility scripts
└── biome.json                   # Biome configuration

Features

✨ Content Validation β€” Validate markdown files against custom schemas with detailed error reporting

🎯 Standard Schema β€” Built on Standard Schema for interoperability

πŸ—οΈ Framework Integration β€” Works seamlessly with Astro, Next.js, and other modern frameworks

πŸ“š Schema Registry β€” Reuse and manage validation schemas across projects

πŸ”„ Markdown Processing β€” Parse and serialize markdown with frontmatter

πŸ€– AI Workflows β€” Model Context Protocol (MCP) server for AI-powered content validation

πŸ› οΈ Biome Plugins β€” Custom GritQL linting rules for migration assistance and best practices

πŸš€ Quick Start

Installation

npm install @watthem/fieldtest
# or
pnpm add @watthem/fieldtest
# or 
yarn add @watthem/fieldtest

Requirements: Node.js 18+ | Works with any package manager

Basic Usage

  1. Define your content schema:
import type { StandardSchemaV1 } from '@watthem/fieldtest';

const blogSchema: StandardSchemaV1 = {
  version: '1',
  name: 'blog-post',
  fields: {
    title: { type: 'string', required: true },
    author: { type: 'string', required: true },
    published: { type: 'boolean', required: true },
    tags: { type: 'string', array: true },
    publishedAt: { type: 'date', required: false }
  }
};
  1. Validate your markdown content:
import { loadUserSchema, validateWithSchema } from '@watthem/fieldtest';

const schema = loadUserSchema(blogSchema);

const markdown = `---
title: "Getting Started with FieldTest"
author: "Jane Developer" 
published: true
tags: ["typescript", "validation", "markdown"]
---

# Getting Started

This post shows how easy it is to validate content with FieldTest!
`;

const result = validateWithSchema(markdown, schema);

if (result.valid) {
  console.log('βœ“ Content validated successfully!');
  // Your content is safe to use
} else {
  console.error('❌ Validation failed:');
  result.errors.forEach(error => {
    console.error(`  β€’ ${error.field}: ${error.message}`);
  });
}

That's it! You're now validating content like a pro. πŸŽ†

🎯 Framework Integration

FieldTest works seamlessly with your favorite framework:

Astro Content Collections

// src/content/config.ts
import { defineCollection } from 'astro:content';
import { loadUserSchema, validateWithSchema } from '@watthem/fieldtest';

const blog = defineCollection({
  type: 'content',
  schema: (z) => z.object({
    title: z.string(),
    author: z.string(),
    publishedAt: z.date()
  }).refine((data) => {
    // Add FieldTest validation on top of Zod
    const result = validateWithSchema(
      generateMarkdown(data), 
      loadUserSchema(blogSchema)
    );
    return result.valid;
  })
});

Next.js Pages & App Router

// Validate content in getStaticProps, generateStaticParams, or API routes
import { validateWithSchema, loadUserSchema } from '@watthem/fieldtest';
import fs from 'fs';

export async function generateStaticParams() {
  const schema = loadUserSchema(blogSchema);
  const posts = fs.readdirSync('./content');
  
  return posts.map(post => {
    const content = fs.readFileSync(`./content/${post}`, 'utf-8');
    const result = validateWithSchema(content, schema);
    
    if (!result.valid) {
      throw new Error(`Invalid post ${post}: ${result.errors.map(e => e.message).join(', ')}`);
    }
    
    return { slug: post.replace('.md', '') };
  });
}

Other Frameworks

// Works with Remix, SvelteKit, Nuxt, Solid, and more!
import { validateWithSchema } from '@watthem/fieldtest';

// Universal validation that works anywhere
const isValid = validateWithSchema(content, schema).valid;

πŸ› οΈ Advanced Features

Built-in Schema Registry

Skip writing schemas for common use cases:

import { getBuiltInSchema } from '@watthem/fieldtest';

// Pre-built schemas for common content types
const blogSchema = getBuiltInSchema('blog-post');
const docsSchema = getBuiltInSchema('documentation');
const marketingSchema = getBuiltInSchema('marketing-copy');

Biome Integration

FieldTest includes custom GritQL plugins for Biome to help with migration and best practices:

// biome.json
{
  "plugins": [
    "./node_modules/@watthem/fieldtest/grit-plugins/fieldtest-migration.grit",
    "./node_modules/@watthem/fieldtest/grit-plugins/schema-usage.grit"
  ]
}
  • βš™οΈ Migration Helper β€” Detects legacy imports and types
  • βœ“ Schema Validation β€” Ensures validation results are checked
  • 🎨 Code Quality β€” Flags non-standard patterns

MCP Integration for AI Workflows

// AI-powered content validation and generation
import { MCPServer } from '@watthem/fieldtest/mcp';

const server = new MCPServer({
  schemas: [blogSchema, docsSchema],
  aiValidation: true
});

πŸ“š Documentation

FieldTest has comprehensive documentation to get you started:

🀝 Contributing

We welcome contributions! FieldTest is open source and built by the community.

Quick Development Setup

# Clone and setup
git clone https://github.com/watthem/fieldtest.git
cd fieldtest
pnpm install

# Start development
pnpm dev       # Watch mode for all packages
pnpm test      # Run tests
pnpm lint      # Check code quality

Ways to Contribute

  • πŸ› Report bugs or request features via GitHub Issues
  • πŸ“ Improve documentation β€” Fix typos, add examples, clarify concepts
  • πŸ› οΈ Add features β€” New schema types, framework integrations, utilities
  • πŸ“Ί Create examples β€” Show how to use FieldTest in different scenarios
  • πŸ”Œ Build integrations β€” Plugins for editors, build tools, or frameworks

Check out our Contributing Guide for detailed guidelines.

πŸ”„ Migration from FKit

Upgrading from FKit or legacy @fieldtest/* packages? We've got you covered:

# Update package.json
npm uninstall @fieldtest/core @fieldtest/validate @fieldtest/registry
npm install @watthem/fieldtest

# Update imports (TypeScript/JavaScript)
find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" | xargs sed -i 's/@fieldtest\/[a-zA-Z-]*/@watthem\/fieldtest/g'
find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" | xargs sed -i 's/FkitDocument/FieldTestDocument/g'

πŸ“ Complete Migration Guide β€” Detailed migration steps and breaking changes

🌍 Community & Support

Join the FieldTest community:

  • πŸ› GitHub Issues β€” Bug reports and feature requests
  • πŸ’¬ GitHub Discussions β€” Questions, ideas, and showcase
  • 🐦 Twitter β€” Updates and announcements
  • πŸ“§ Email β€” Direct contact for partnerships or support

πŸ“œ License

MIT License Β© 2024 Matthew Hendricks

Free to use in personal and commercial projects. See LICENSE for details.

πŸš€ Built With

FieldTest stands on the shoulders of giants:

  • πŸ“¦ Standard Schema β€” Universal validation interface
  • βš›οΈ TypeScript β€” Type-safe development experience
  • πŸ“¦ pnpm + Turborepo β€” Fast, reliable monorepo management
  • πŸ€– Biome β€” Fast formatting and linting
  • ⚑ Vitest β€” Blazing fast unit testing

Ready to validate your content like a pro?

Get Started β€’ See Examples β€’ Star on GitHub

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •