Skip to content
XenonDocs
Esc
    GitHub
    Docs

    defineCollection

    API reference for the defineCollection function, collection configuration options, and validation rules.

    On this page

    Overview

    The defineCollection function declares a content collection schema with TypeScript type inference.

    TypeScript
    import { defineCollection, text } from "xenon-cms";
    
    export const posts = defineCollection({
      slug: "posts",
      labels: { singular: "Post", plural: "Posts" },
      slugFrom: "title",
      drafts: true,
      upload: false,
      admin: {
        useAsTitle: "title",
        defaultColumns: ["title", "status"],
      },
      fields: {
        title: text({ required: true }),
      },
    });

    The function performs light runtime verification of the schema structure and preserves literal types for downstream inference.

    Configuration options

    OptionTypeDefaultNotes
    slugstringRequiredUnique identifier matching /^[a-z][a-z0-9-]*$/. Cannot be auth, _files, or start with _.
    fieldsRecord<string, Field>RequiredObject map of field definitions keyed by name. Cannot use reserved system keys.
    labels{ singular?: string; plural?: string }Humanized slugDisplay labels used throughout the admin dashboard.
    slugFromstringundefinedKey of a declared text field used to derive document slugs.
    draftsbooleantrueEnables draft saving and publishing workflows. Ignored on upload collections.
    uploadboolean | UploadConfigfalseEnables binary asset management and injects system media fields.
    adminCollectionAdminOptions{}useAsTitle, defaultColumns, group and description for the admin's list and sidebar.
    accessCollectionAccessDefault rulesAuthorization callback functions for CRUD operations.

    admin options

    The admin object customizes how collection records display in /admin:

    OptionTypeDefaultNotes
    useAsTitlestring"id"Field key rendered as the document title in breadcrumbs and selects.
    defaultColumnsstring[]["id", "createdAt"]Keys displayed as columns in the collection list table. Accepts field keys and system keys (id, slug, status, createdAt, updatedAt).
    groupstringundefinedSidebar navigation group header.
    descriptionstringundefinedHelp text or summary displayed for the collection in the admin dashboard.

    upload options

    When upload is configured as an object:

    OptionTypeDefaultNotes
    mimeTypesstring[]All typesArray of permitted MIME types or wildcards (e.g., ["image/*"]).
    maxFileSizenumberUnlimitedMaximum permitted file size in bytes.

    Next steps