Making SvelteKit forms a pleasure to use with comprehensive validation, type safety, and progressive enhancement.
—
Unified adapters for 12+ popular validation libraries, providing consistent interface and type inference across different schema validation approaches. Enables seamless integration with any validation library while maintaining type safety and consistent behavior.
Adapters for Zod validation library supporting both v3 and v4, with complete type inference and JSON Schema generation.
/**
* Creates a Zod v3 validation adapter
* @param schema - Zod schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function zod<T>(
schema: ZodObjectType<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a Zod v3 client-side validation adapter
* @param schema - Zod schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function zodClient<T>(
schema: ZodObjectType<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates a Zod v4 validation adapter
* @param schema - Zod v4 schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function zod4<T>(
schema: ZodValidationSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a Zod v4 client-side validation adapter
* @param schema - Zod v4 schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function zod4Client<T>(
schema: ZodValidationSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type ZodObjectType = z.ZodObject<any, any, any>;
type ZodValidationSchema<T> = z.ZodSchema<T>;Usage Examples:
import { z } from "zod";
import { zod, zodClient } from "sveltekit-superforms/adapters";
// Define schema
const schema = z.object({
name: z.string().min(2).max(50),
email: z.string().email(),
age: z.number().min(18).max(120),
tags: z.array(z.string()).optional()
});
// Server-side validation
export const load = async () => {
const form = await superValidate(zod(schema));
return { form };
};
// Client-side validation
const { form, enhance } = superForm(data.form, {
validators: zodClient(schema)
});Adapter for Yup validation library with complete schema introspection and type inference.
/**
* Creates a Yup validation adapter
* @param schema - Yup schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function yup<T>(
schema: YupSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a Yup client-side validation adapter
* @param schema - Yup schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function yupClient<T>(
schema: YupSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type YupSchema<T> = import("yup").Schema<T>;Usage Examples:
import * as yup from "yup";
import { yup as yupAdapter, yupClient } from "sveltekit-superforms/adapters";
const schema = yup.object({
name: yup.string().required().min(2),
email: yup.string().email().required(),
age: yup.number().positive().integer().min(18)
});
// Server validation
const form = await superValidate(yupAdapter(schema));
// Client validation
const { form } = superForm(data.form, {
validators: yupClient(schema)
});Adapter for Joi validation library with full schema support and constraint extraction.
/**
* Creates a Joi validation adapter
* @param schema - Joi schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function joi<T>(
schema: JoiSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a Joi client-side validation adapter
* @param schema - Joi schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function joiClient<T>(
schema: JoiSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type JoiSchema<T> = import("joi").Schema<T>;Usage Examples:
import Joi from "joi";
import { joi, joiClient } from "sveltekit-superforms/adapters";
const schema = Joi.object({
name: Joi.string().min(2).required(),
email: Joi.string().email().required(),
age: Joi.number().integer().min(18).required()
});
const form = await superValidate(joi(schema));Adapter for Valibot validation library with type-safe schema definitions and modern API.
/**
* Creates a Valibot validation adapter
* @param schema - Valibot schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function valibot<T>(
schema: ValibotSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a Valibot client-side validation adapter
* @param schema - Valibot schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function valibotClient<T>(
schema: ValibotSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type ValibotSchema<T> = import("valibot").BaseSchema<T>;Usage Examples:
import * as v from "valibot";
import { valibot, valibotClient } from "sveltekit-superforms/adapters";
const schema = v.object({
name: v.pipe(v.string(), v.minLength(2)),
email: v.pipe(v.string(), v.email()),
age: v.pipe(v.number(), v.minValue(18))
});
const form = await superValidate(valibot(schema));Adapter for ArkType validation library with advanced type inference and runtime validation.
/**
* Creates an ArkType validation adapter
* @param schema - ArkType schema definition
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function arktype<T>(
schema: ArktypeSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates an ArkType client-side validation adapter
* @param schema - ArkType schema definition
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function arktypeClient<T>(
schema: ArktypeSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type ArktypeSchema<T> = import("arktype").Type<T>;Usage Examples:
import { type } from "arktype";
import { arktype, arktypeClient } from "sveltekit-superforms/adapters";
const schema = type({
"name": "string>=2",
"email": "string.email",
"age": "number>=18"
});
const form = await superValidate(arktype(schema));Adapter for TypeBox validation library with JSON Schema compatibility and TypeScript integration.
/**
* Creates a TypeBox validation adapter
* @param schema - TypeBox schema object
* @param options - Optional adapter configuration
* @returns ValidationAdapter for server and client use
*/
function typebox<T>(
schema: TypeboxSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
/**
* Creates a TypeBox client-side validation adapter
* @param schema - TypeBox schema object
* @param options - Optional adapter configuration
* @returns ClientValidationAdapter for client-only use
*/
function typeboxClient<T>(
schema: TypeboxSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
type TypeboxSchema<T> = import("@sinclair/typebox").TSchema;Usage Examples:
import { Type } from "@sinclair/typebox";
import { typebox, typeboxClient } from "sveltekit-superforms/adapters";
const schema = Type.Object({
name: Type.String({ minLength: 2 }),
email: Type.String({ format: "email" }),
age: Type.Number({ minimum: 18 })
});
const form = await superValidate(typebox(schema));Additional validation library adapters supporting various other popular validation libraries.
/**
* Creates a Superstruct validation adapter
*/
function superstruct<T>(
schema: SuperstructSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
function superstructClient<T>(
schema: SuperstructSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates a Class-validator adapter
*/
function classvalidator<T>(
schema: ClassValidatorSchema<T>,
options?: RequiredDefaultsOptions<T>
): ValidationAdapter<T>;
function classvalidatorClient<T>(
schema: ClassValidatorSchema<T>,
options?: RequiredDefaultsOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates an Effect-ts schema adapter
*/
function effect<T>(
schema: EffectSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
function effectClient<T>(
schema: EffectSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates a VineJS validation adapter
*/
function vine<T>(
schema: VineSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
function vineClient<T>(
schema: VineSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates a Schemasafe adapter
*/
function schemasafe<T>(
schema: SchemasafeSchema<T>,
options?: AdapterOptions<T>
): ValidationAdapter<T>;
function schemasafeClient<T>(
schema: SchemasafeSchema<T>,
options?: AdapterOptions<T>
): ClientValidationAdapter<T>;
/**
* Creates a custom superform client-side adapter
*/
function superformClient<T>(
validate: (data: unknown) => Promise<ValidationResult<T>>,
options?: { shape?: SchemaShape }
): ClientValidationAdapter<T>;Usage Examples:
// Superstruct
import { object, string, number } from "superstruct";
import { superstruct } from "sveltekit-superforms/adapters";
const schema = object({
name: string(),
age: number()
});
const form = await superValidate(superstruct(schema));
// Class-validator
import { IsEmail, IsString, Min } from "class-validator";
import { classvalidator } from "sveltekit-superforms/adapters";
class UserDto {
@IsString()
name: string;
@IsEmail()
email: string;
@Min(18)
age: number;
}
const form = await superValidate(classvalidator(UserDto, {
defaults: { name: "", email: "", age: 0 }
}));
// Custom validation
const form = await superValidate(superformClient(async (data) => {
// Custom validation logic
if (typeof data !== 'object' || !data) {
return { success: false, issues: [{ path: [], message: 'Invalid data' }] };
}
return { success: true, data: data as T };
}));Configuration options available for all validation adapters.
interface AdapterOptions<T> {
/** JSON Schema to use instead of generating one */
jsonSchema?: JSONSchema;
/** Default values to use for the schema */
defaults?: T;
}
interface RequiredDefaultsOptions<T> {
/** Required default values (for adapters that can't infer defaults) */
defaults: T;
/** Optional JSON Schema */
jsonSchema?: JSONSchema;
}
interface ValidationAdapter<Out, In = Out> {
/** Identifier for the validation library */
superFormValidationLibrary: ValidationLibrary;
/** Validation function */
validate: (data: unknown) => Promise<ValidationResult<Out>>;
/** JSON Schema representation */
jsonSchema: JSONSchema;
/** Default values */
defaults: Out;
/** HTML input constraints */
constraints: InputConstraints<Out>;
/** Schema structure metadata */
shape: SchemaShape;
/** Unique identifier for caching */
id: string;
}
interface ClientValidationAdapter<Out, In = Out> {
/** Identifier for the validation library */
superFormValidationLibrary: ValidationLibrary;
/** Client-side validation function */
validate: (data: unknown) => Promise<ValidationResult<Out>>;
/** Optional schema structure metadata */
shape?: SchemaShape;
}
type ValidationLibrary =
| 'arktype'
| 'classvalidator'
| 'custom'
| 'joi'
| 'superform'
| 'typebox'
| 'valibot'
| 'yup'
| 'zod'
| 'zod4'
| 'vine'
| 'schemasafe'
| 'superstruct'
| 'effect';
interface ValidationResult<T> {
/** Whether validation succeeded */
success: boolean;
/** Validated data (if successful) */
data?: T;
/** Validation issues (if failed) */
issues?: ValidationIssue[];
}
interface ValidationIssue {
/** Path to field with error */
path: (string | number)[];
/** Error message */
message: string;
/** Error code */
code?: string;
}All adapters provide the same interface, making it easy to switch between validation libraries:
// Easy to switch from Zod...
const form = await superValidate(zod(zodSchema));
// ...to Yup
const form = await superValidate(yup(yupSchema));
// ...to Valibot
const form = await superValidate(valibot(valibotSchema));
// Client-side works the same way
const { form } = superForm(data.form, {
validators: zodClient(schema) // Zod
// validators: yupClient(schema) // Yup
// validators: valibotClient(schema) // Valibot
});type Schema = any; // Generic schema type that works with all adapters
type Infer<T> = T extends ValidationAdapter<infer Out, any> ? Out : never;
type InferIn<T> = T extends ValidationAdapter<any, infer In> ? In : never;
interface JSONSchema {
type?: string;
properties?: Record<string, JSONSchema>;
required?: string[];
items?: JSONSchema;
minLength?: number;
maxLength?: number;
minimum?: number;
maximum?: number;
pattern?: string;
format?: string;
enum?: any[];
default?: any;
title?: string;
description?: string;
}
interface SchemaShape {
[key: string]: SchemaFieldType | SchemaShape | SchemaShape[];
}
type SchemaFieldType =
| 'string'
| 'number'
| 'integer'
| 'boolean'
| 'object'
| 'array'
| 'null'
| 'file'
| 'date'
| 'bigint';
interface InputConstraints<T> {
[K in keyof T]?: T[K] extends Record<string, unknown>
? InputConstraints<T[K]>
: T[K] extends Array<infer U>
? U extends Record<string, unknown>
? Array<InputConstraints<U> | undefined>
: InputConstraint
: InputConstraint;
}
interface InputConstraint {
min?: number;
max?: number;
step?: number;
minlength?: number;
maxlength?: number;
pattern?: string;
required?: boolean;
}Install with Tessl CLI
npx tessl i tessl/npm-sveltekit-superforms