Reference
Schema API
A schema says what shape content has. Val reads it to type your code, to validate content, and to give each field the right editor in the Studio.
Use it for
- Deciding what editors can change, and what they cannot
- Typing content end to end, from the .val.ts file to the component
Schema
Val provides a comprehensive set of schema types to define your content structure. Each schema type has its own methods and validation options.
Available Schema Types
s.string()
Text values with validation and rendering options
s.number()
Numeric values with min/max validation
s.boolean()
True/false values
s.literal()
Fixed literal values, used with unions
s.date()
Date values (date-only, not datetime) with ISO 8601 formatting
s.object()
Complex objects with defined properties
s.array()
Lists of items with a defined schema
s.record()
Key-value pairs with dynamic keys
s.route()
Route references validated against router modules
s.router()
Shorthand for creating router configurations
s.discriminatedUnion()
One of several object shapes, told apart by a tag
s.enum()
One of a fixed set of strings
s.int()
A whole number, optionally edited with a slider
s.color()
A colour, stored as a CSS colour string
s.code()
Source code, edited in a code editor
s.video()
A video, as an mp4 or an HLS stream
s.font()
A font picked from a font library
s.view()
Show another module from this one
s.settings()
The project's settings module
s.keyOf()
References to keys in other Val modules
s.image()
Image files with metadata and remote support
s.imagedir()
An image gallery: a whole module of images, in one directory, that fields can pick from
s.file()
Generic files including videos and documents
s.filedir()
A directory of files of any type, as a whole module
s.fontdir()
A directory of web fonts that fields pick from with s.font()
s.videodir()
A directory of videos that fields pick from with s.video()
s.richtext()
Formatted text with configurable options