Collection administration and publishing

@dash/cms is an optional server-side package for Dash consumer apps. It provides collection administration as ordinary SDUI page modules and a MessagePack CRUD service over @dash/data. It does not add an admin UI dependency to the data package, create a second database, or register public routes merely by installing the package.The first version supports collection navigation, paginated record lists, generated create/edit forms, confirmed deletion, and an opt-in draft/published lifecycle. It uses the existing Dash client, components, form state, route data, and mutation invalidation.Collection and record cards open from their full surface and support keyboard navigation. Delete remains a separate control. When hosted in Admin, the Back button returns to the previous CMS page, including the originating list page, and asks before discarding unsaved form changes. All collections and Records links provide direct navigation to parent views.

Define content

Use an ordinary defineCollection collection for administration without publishing. Use defineContentCollection for content whose public visibility depends on publication status:
ts
// src/collections/posts.ts
import { defineContentCollection } from "@dash/cms/content";

export const posts = defineContentCollection({
  slug: "posts",
  labels: { singular: "Post", plural: "Posts" },
  timestamps: true,
  fields: [
    { type: "id" },
    { name: "title", type: "text", required: true, maxLength: 200 },
    { name: "body", type: "text", required: true, maxLength: 20000 },
    { name: "featured", type: "boolean", defaultValue: false },
  ],
});
Import collection helpers from @dash/cms/content. This data-only entry point keeps schema tools such as drizzle-kit from loading the server, SSR, or browser runtime. The root @dash/cms entry point provides the service and page factories.Export posts through the app's appCollections array in src/collections/index.ts, as with any Dash collection. Keep each collection in its own module so codegen discovers it. Run bun run codegen and the app's schema update command (bun run db:push in the CLI template).The helper reserves publicationStatus, a select field containing draft and published. New records default to draft through a composed beforeValidate hook, including Local API creates. Existing application hooks are preserved. For an existing table, review/backfill publication status deliberately before making that collection public.Default create/update/delete access is access.admin. Default public read access is constrained to published records. Editors can read drafts; by default editors are principals satisfying access.admin. The optional second argument accepts { isEditor: (user) => boolean } to customize who may read drafts. This does not grant write access. Explicit collection access rules override the default write rules. An explicit read rule still applies to editors and is combined with the published-record constraint for other readers, preserving tenant/owner scopes.

Create the service

ts
// src/cms.ts — server-only module
import { createCmsService } from "@dash/cms/server";
import { createDefaultDataUserResolver } from "@dash/server";
import { data } from "@dash/generated/data";

export const getUser = createDefaultDataUserResolver({ publicOwnerId: false });
export const cms = createCmsService({
  data,
  collections: ["posts"],
  getUser,
  basePath: "/cms",
  pageSize: 25,
});
collections is an explicit allowlist. Every slug must exist in the Local API. Only simple URL-segment slugs (letters, numbers, underscores, and hyphens) are accepted. pageSize is an integer from 1 to 100; the default is 25.Admission to the CMS requires a non-null administrator by default. Supply canAccess(user) for an application-specific CMS role; this additional gate does not override collection access. Every query/mutation forwards the resolved user and request to the Local API with overrideAccess: false. Reuse the application's trusted identity resolver. The package does not provide a login page, create accounts, or grant the default development principal administrator rights.The default Dash resolver uses development headers locally and validated JWTs in production. Configure the app's normal client authentication so page requests and RPC requests carry the same identity. Do not promote anonymous production users to administrators. See database and authentication.Register the service's query resolvers in app configuration:
ts
// dash.config.ts
import type { DashAppConfig } from "@dash/server";
import { cms, getUser } from "./src/cms";

export default {
  getUser,
  queryResolvers: cms.queryResolvers,
} satisfies DashAppConfig;
Merge with other application query resolvers when needed. The service owns the cms.access, cms.list, and cms.record source names. It may also be used with startDashApi by passing data, getUser, and queryResolvers explicitly.

Mount the pages and API

Page modules come from cms.pages. Expose each module with a small file-based route; no changes to the client router are needed:
ts
// src/app/cms/posts/index.tsx
import { cms } from "../../../cms";

const page = cms.pages.collections.posts.list;
export const route = page.route;
export default page.default;
Use these page mappings, adjusting the import's relative path in each file:
Consumer file
Page module
src/app/cms/index.tsxcms.pages.index
src/app/cms/posts/index.tsxcms.pages.collections.posts.list
src/app/cms/posts/page/[page].tsxcms.pages.collections.posts.paginated
src/app/cms/posts/new.tsxcms.pages.collections.posts.create
src/app/cms/posts/records/[id].tsxcms.pages.collections.posts.edit
Repeat the four collection routes for each managed collection. If basePath is changed, place the page files under that path. Record IDs are URL-encoded and the dedicated records segment avoids collisions with IDs such as new or page.Mount the shared CRUD handler at the fixed API path:
ts
// src/app/api/rpc/cms/[collection].ts
import { cms } from "../../../../cms";

export const GET = cms.handleApi;
export const POST = cms.handleApi;
export const PATCH = cms.handleApi;
export const DELETE = cms.handleApi;
Then run codegen and start the app normally. API calls use the Dash MessagePack transport. Native number input strings are converted to finite numbers before the collection validator runs. Unknown fields, invalid publication states, required-field failures, and denied operations remain errors from the data layer. Successful mutations invalidate the collection query key. Deleting an inaccessible or missing ID is an idempotent no-op, matching Dash CRUD behavior.createCmsPages(collections, { basePath }) is also exported for consumers that want to build the UI modules independently of service initialization. The matching CMS query resolvers and API still need to be mounted.

Publishing behavior and scope

Saving a draft keeps it hidden from non-editor reads. Publishing changes the saved record's status to published; unpublishing returns it to draft. The edit screen includes status selection and explicit controls for publishing or unpublishing the saved record. These controls reset the form to the freshly loaded record, so unsaved changes are discarded; save edits first.This is a single-record workflow. Editing and saving a published record updates the live content immediately. There is no separate working draft beside a live revision, revision history, scheduled publishing, approval workflow, media library, or rich-text editor in this first version. Text, number, boolean, select, and timestamp fields use the current Dash controls. IDs, ownership fields, and automatically managed timestamps are omitted from write forms. Collection hooks and validation remain the source of truth.CMS schema lists do not evaluate dynamic operation permissions to hide every button. Literal false create/update/delete rules affect the UI; conditional rules are enforced by the server on each operation. Installing this package does not change any existing app collection or turn on product writes.

Package development

Framework source is in packages/cms. The service enforces anonymous admission, collection allowlists, denied writes, row ownership, pagination, input validation, and draft/publish/unpublish/delete behavior; there is no automated test suite, so exercise a change against a running app (Admin's Content tool is the quickest way). Run bun run check in the framework repo. The normal package release workflow builds and publishes @dash/cms after its dependencies.

Multiple applications

Use the central admin console to host administration separately and select among multiple applications through one authenticated endpoint. Each application explicitly enables its services through its connector.