Field reference
Every field builder, its options, the value your code receives, and the rules AtMyApp enforces.
Open with AI
Import s from @atmyapp/structure (also re-exported by @atmyapp/core). Every builder takes an options object. For when to use which, read Design your schema.
Options are either rules, which AtMyApp enforces when content is saved, published or submitted through a form, or hints, which guide the editor and the AI assistant. The tables say which is which.
At a glance
Section titled “At a glance”| Builder | Your code receives | Typical use |
|---|---|---|
s.string() |
string |
Headings, labels, short text |
s.shortText() / s.longText() |
string |
A line / a paragraph |
s.markdown() |
string (Markdown) |
Formatted body text |
s.email() / s.url() |
string |
Contact address, link |
s.number() / s.integer() |
number |
Prices, counts |
s.boolean() |
boolean |
On/off switches |
s.date() / s.datetime() / s.timestamp() |
string |
"2026-10-21", "2026-10-21T18:00:00+02:00" |
s.enum({ values }) |
one of values |
Fixed choices |
s.union({ variants }) |
any variant’s value | Mixed values |
s.object({ fields }) |
object | A group of fields |
s.array({ items }) |
array | A short repeated list |
s.image() / s.file() |
{ url, … } |
One image or file |
s.gallery() |
{ url, … }[] |
Several images |
s.reference(target) |
string (ID) or string[] |
Link to a collection entry |
s.slug({ source }) |
string |
URL identifier |
s.order() |
number |
Editor-controlled order |
s.mdx({ config }) |
string (MDX) |
Rich content with your components |
Options on every field
Section titled “Options on every field”| Option | Kind | Meaning |
|---|---|---|
description |
hint | What the field is for and where it appears. Shown to editors and the AI assistant. |
optional |
rule | true lets the field be missing. Fields are required by default. |
nullable |
rule | true also accepts an explicit null, so editors can clear the value. |
default |
hint | Pre-fills new content. It doesn’t change content that already exists. |
localize |
rule | Translate this field. Only string and MDX fields. See Translations. |
unique |
rule | No two collection entries may share the value. Top-level, non-translated collection fields only. |
ui, storage |
advanced | Editor and storage metadata. Most schemas don’t need them. |
Use optional rather than required: false; they mean the same thing.
subtitle: s.string({ optional: true }), // may be missinglogo: s.image({ optional: true, nullable: true }), // may be missing or cleareds.string({ min: 1, max: 80, placeholder: "A clear headline" });s.shortText({ description: "One line under the photo." });s.longText({ max: 600 });s.markdown();s.email();s.url({ optional: true });s.string({ pattern: "^[A-Z]{3}$", description: "Three-letter airport code" });| Builder | Same as s.string() with |
|---|---|
shortText |
format: "short", preferredLength: 80, localize: true |
longText |
format: "long", preferredLength: 280, localize: true |
markdown |
format: "markdown", preferredLength: 1200, localize: true |
email |
format: "email" |
url |
format: "url" |
| Option | Kind | Meaning |
|---|---|---|
min, max |
rule | Minimum and maximum length in characters. (minLength / maxLength also work.) |
pattern |
rule | A regular expression the whole value must match. |
format: "email" |
rule | Must look like an email address. |
format: "url" |
rule | Must be an absolute http or https URL. |
enumValues |
rule | Allowed values. Prefer s.enum(). |
format (other values) |
hint | short, long, markdown, code, textarea: picks the editor. |
preferredLength |
hint | Ideal length for writing and AI suggestions. Not a limit. |
placeholder, examples |
hint | Input guidance. Not stored. |
localize: true on the text presets is harmless in projects without translations. Markdown is stored as text: render it with your Markdown library. Plain strings are never HTML.
Numbers
Section titled “Numbers”s.number({ min: 0, max: 100 });s.integer({ min: 1, default: 1 });s.number({ format: "currency", description: "Price in EUR, including VAT" });| Option | Kind | Meaning |
|---|---|---|
min, max |
rule | Inclusive bounds. (minimum / maximum also work.) |
integer: true |
rule | Whole numbers only. s.integer() sets it for you. |
format |
hint | integer, percent or currency. Put the unit in the description. |
step |
hint | Increment for the editor’s number input. |
Booleans
Section titled “Booleans”s.boolean({ default: false });Dates and times
Section titled “Dates and times”s.date(); // "2026-10-21"s.datetime(); // "2026-10-21T18:00:00+02:00"s.timestamp(); // "2026-10-21T16:00:00Z"Values are ISO strings, not Date objects. Dates must be real calendar dates (YYYY-MM-DD). Date-times and timestamps must include a time zone. Parse them in your code when you need to format them.
Choices and unions
Section titled “Choices and unions”s.enum({ values: ["lunch", "dinner"], default: "dinner" });s.union({ variants: [s.string(), s.number()] });enum.values can contain strings, numbers, booleans and null. A union value must match at least one variant.
Objects
Section titled “Objects”s.object({ fields: { label: s.string(), href: s.url() }, additionalProperties: false,});| Option | Kind | Meaning |
|---|---|---|
fields |
rule | The child fields. Each child has its own optional. |
additionalProperties: false |
rule | Reject properties that aren’t declared. |
Translate the leaf fields, not the object.
Arrays
Section titled “Arrays”s.array({ items: s.string(), minItems: 1, maxItems: 5 });s.array({ items: s.object({ fields: { title: s.string(), text: s.string() } }) });| Option | Kind | Meaning |
|---|---|---|
items |
rule | The field definition for every item. Required. |
minItems, maxItems |
rule | How many items are allowed. |
uniqueItems |
rule | No duplicate items. |
identityField |
rule | Name of a stable, non-translated field that identifies each object item. Optional. |
Object items carry a stable _key that survives edits, reordering and translation. Use it as a render key. The array’s order is the order editors set.
Images, files and galleries
Section titled “Images, files and galleries”s.image({ config: { optimizeFormat: "webp", ratioHint: { x: 16, y: 9 } } });s.file({ accept: ["application/pdf"] });s.gallery({ optional: true });Your code receives each asset as an object with a url (images may also have alt). Galleries are a list of them:
<img src={post.cover.url} alt={post.cover.alt ?? ""} />{post.photos.map((photo) => <img src={photo.url} alt={photo.alt ?? ""} />)}| Option | Kind | Meaning |
|---|---|---|
accept |
hint | Media types the editor offers, such as ["application/pdf"]. Form uploads have their own type rules. |
config.optimizeFormat |
hint | webp or none. |
config.optimizeLoad |
hint | progressive or none. |
config.ratioHint |
hint | Suggested aspect ratio, { x, y }. |
config.maxSize |
hint | Suggested maximum { width, height }. |
In forms, the same builders accept uploaded files instead.
References
Section titled “References”s.reference("authors");s.reference({ target: "posts", multiple: true, optional: true });s.reference({ target: "posts", by: "slug" });| Option | Default | Meaning |
|---|---|---|
target |
— | The collection to link to. Required. |
multiple |
false |
Store a list of references. |
by |
"id" |
Store the target’s id or its slug. Slug references need an s.slug() field named slug on the target. |
Your code receives the ID (or slug) as a string, or a list of strings. Fetch the targets yourself: see Resolve references. AtMyApp refuses to publish a reference to a missing entry, and blocks deleting an entry that is still referenced.
s.slug({ source: "title" });A stable URL identifier: up to 96 lowercase letters, numbers and single hyphens. It’s generated from source when the entry is created, it’s unique within the collection, and it never changes afterwards, so published links keep working. Slugs can’t be made editable or non-unique.
s.order();s.order({ groupBy: "category" });Lets editors arrange collection entries. The value is an integer rank; sort by it in your code. It must be a top-level collection field. groupBy names a single-value reference field and keeps a separate order per referenced entry.
export default defineSchema({ mdx: { article: { description: "Article body with approved callouts.", components: { Callout: { description: "A highlighted note.", props: { tone: "string" } }, }, }, }, definitions: { posts: defineCollection({ fields: { body: s.mdx({ config: "article" }) }, }), },});config names an entry in the schema’s mdx map. It tells editors and the AI assistant which components they may use. Your website renders the MDX and provides the components. Only enable what your renderer supports.
