Standard Schema Support
@cleverbrush/schema implements the Standard Schema v1 specification. This means every schema you build is immediately usable in 50+ libraries and frameworks without any adapter or wrapper — including tRPC, TanStack Form, React Hook Form, T3 Env, Hono, Elysia, and next-safe-action.
The ~standard property
All 13 builders expose a ['~standard'] getter on the base SchemaBuilder class. The property returns a cached object with three fields:
| Field | Value | Description |
|---|---|---|
version | 1 | Standard Schema spec version |
vendor | '@cleverbrush/schema' | Library identifier |
validate(value) | sync function | Wraps .validate() and returns { value } on success or { issues: [{ message }] } on failure |
Usage
You can access ['~standard'] directly, but in practice you never need to — just pass a @cleverbrush/schema builder directly wherever a Standard Schema validator is expected:
import { object, string, number } from '@cleverbrush/schema';
const UserSchema = object({
name: string().minLength(2),
email: string().email(),
age: number().min(18).optional(),
});
// Direct access — useful for testing or custom integrations
const std = UserSchema['~standard'];
console.log(std.version); // 1
console.log(std.vendor); // '@cleverbrush/schema'
const ok = std.validate({ name: 'Alice', email: 'alice@example.com' });
// { value: { name: 'Alice', email: 'alice@example.com', age: undefined } }
const fail = std.validate({ name: 'A', email: 'not-an-email' });
// { issues: [{ message: 'minLength' }, { message: 'email' }] }TanStack Form
Pass any @cleverbrush/schema builder directly as a TanStack Form field validator — no adapter needed:
import { useForm } from '@tanstack/react-form';
import { standardSchemaValidator } from '@tanstack/react-form/standard-schema';
import { string } from '@cleverbrush/schema';
const emailSchema = string().email('Please enter a valid email');
const form = useForm({
validatorAdapter: standardSchemaValidator(),
defaultValues: { email: '' },
});
// In JSX:
// <form.Field
// name="email"
// validators={{ onChange: emailSchema, onBlur: emailSchema }}
// />T3 Env
Use @cleverbrush/schema builders as T3 Env server and client environment validators:
import { createEnv } from '@t3-oss/env-nextjs';
import { string, number } from '@cleverbrush/schema';
export const env = createEnv({
server: {
DATABASE_URL: string().url(),
PORT: number().min(1).max(65535).optional(),
},
client: {
NEXT_PUBLIC_API_URL: string().url(),
},
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
PORT: process.env.PORT ? Number(process.env.PORT) : undefined,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
},
});External Schema Interop — extern()
Standard Schema is bidirectional. @cleverbrush/schema exposes its schemas to other tools via ['~standard'], and it can consume schemas from other libraries via extern(). Wrap any Standard Schema v1 compatible schema (Zod, Valibot, ArkType, …) into a native builder — no rewriting needed:
import { z } from 'zod';
import { object, number, extern, type InferType } from '@cleverbrush/schema';
// Keep your existing Zod schema as-is
const ZodAddress = z.object({
street: z.string().min(1),
city: z.string(),
zip: z.string().length(5),
});
// Compose with @cleverbrush/schema
const OrderSchema = object({
address: extern(ZodAddress),
totalCents: number().min(1),
});
// Type is inferred from both libraries automatically
type Order = InferType<typeof OrderSchema>;
// { address: { street: string; city: string; zip: string }; totalCents: number }
const result = OrderSchema.validate({
address: { street: '5th Ave', city: 'NYC', zip: '10001' },
totalCents: 4999,
});
if (!result.valid) {
// Navigate into the extern property — no type annotation needed
const zipErrors = result.getErrorsFor(t => t.address.zip);
console.log(zipErrors.errors);
}extern()takes a single parameter — the external schema. Types and property descriptors are derived automatically. Validation is delegated to the external library's ['~standard'].validate() method, so @cleverbrush/schemanever re-implements another library's validation logic.
Compatible tools
Any library that consumes Standard Schema v1 validators works with @cleverbrush/schema automatically:
| Library | Category | Integration |
|---|---|---|
| TanStack Form | Forms | Live showcase → |
| T3 Env | Env validation | Live showcase → |
| tRPC | API / RPC | Pass schema as procedure .input() |
| React Hook Form | Forms | standardSchemaResolver(schema) |
| Hono | HTTP framework | Validator middleware |
| Elysia | HTTP framework | Route body / query validation |
| next-safe-action | Server actions | Action input validation |
| TanStack Router | Routing | Search param validation |
See the full list of Standard Schema adopters at standardschema.dev.