Skip to content
Auto
English

Content types

Content types live in cms.content.ts, a TypeScript file next to your schema:

cms.content.ts
import { defineContent, field } from "@tapedb/cms";
export const content = defineContent({
author: {
name: field.string({ required: true, max: 80 }),
portrait: field.image(),
bio: field.richText(),
},
post: {
title: field.string({ required: true, max: 120 }),
slug: field.slug({ required: true }),
summary: field.string({ max: 280, multiline: true }),
cover: field.image(),
body: field.richText({ required: true }),
author: field.reference("author", { required: true }),
related: field.reference("post", { weak: true }),
section: field.select(["News", "Features", "Opinion"]),
featured: field.boolean({ label: "Feature on the front page" }),
publishOn: field.date({ description: "The date shown on the article." }),
},
});

defineContent returns the types and the models they compile to, which the schema takes as an extension: schema(models, { extensions: [content] }). After changing a type, run npx @tapedb/cli migrate dev --name <what changed> and commit the migration.

Field Stores Options
field.string() text max characters, pattern (a RegExp), multiline for a text area
field.slug() lowercase words joined by hyphens, unique among the type’s published documents the studio fills it from the title on request
field.number() a number min, max
field.boolean() true or false
field.select(options) one string from a fixed list
field.date() a date, "2026-11-28" time: true for a date and time, stored as ISO UTC
field.richText() a document of paragraphs, headings, lists, quotes, code blocks, rules and line breaks, with bold, italic and links, as ProseMirror JSON lock (default) or collaborative: true, see co-editing
field.reference(type) a document of another type weak: true for a reference that may point at nothing
field.image() { path, alt, x, y }: a file under public/ and its focal point
field.json() any JSON value usually with a custom input

Every field also takes:

  • required: a draft may leave it empty, but publishing refuses until it is filled;
  • label: the name the studio shows, in place of the field name;
  • description: help text under the label;
  • input: the name of a custom input from your studio extension.

A reference stores the id of a document of another type. In the published document and in the delivery routes it appears as <field>Id (strong) or <field>Ref (weak):

  • Strong (field.reference("author")) is a foreign key. The referenced document cannot be deleted while anything refers to it; the studio says so and the reference has to go first.
  • Weak (field.reference("post", { weak: true })) may point at a document that was never published or no longer exists. Use it for “related” links that should not hold anything in place.

The delivery routes and the website SDK can expand references into the documents they point at.

An image field holds a file path under public/, an alternative text, and a focal point (x and y from 0 to 1). Editors upload images to the media library or straight into the field, and click the image to set the focal point; the field shows the wide, square and tall crops it produces. The delivery path crops around that point at any size you ask for. See Images.

Each content type compiles to four TapeDB models, named after the type:

Model Holds
post the published values, with rev and publishedAt
postDraft the working copy, one per document, with editedBy (the last person to write it)
postRevision an immutable snapshot of each publish and unpublish
postVersion the document’s values inside a release, with the revision they were based on

Two more models serve every type: cmsRelease for releases and cmsPerson for each person’s display name, which each person writes for themselves so the studio shows names rather than ids.

These are ordinary TapeDB models. Your app can query them with the TapeDB client like any other, under the CMS’s rules: readers see published documents only; contributors and up also see unpublished ones, drafts, revisions and versions.

Adding a field or a type is an additive migration. Removing or renaming one changes stored data, so migrate dev asks for --accept-data-loss or a rename hint, as for any TapeDB model. See Migrations.

A new required field does not invalidate documents already published: the rule applies when a document is next published.