Skip to content
Auto
English

Publishing and releases

Every document has at most one draft beside its published values. Editing writes the draft; the published document does not move until someone publishes. Publishing copies the draft into the document as the next revision, writes an immutable revision snapshot, and removes the draft. All of that is one transaction.

Each document carries rev, which every write advances by one. Publishing names the revision it was based on, and the server refuses it if the document has moved since. Two editors who publish from the same revision at the same moment: exactly one lands, and the other is told the document changed.

The server enforces the rest of publishing too:

  • A draft may be incomplete. A published document must have every required field and pass every field’s checks (lengths, patterns, numbers within range, a known select option, a well-formed slug or date, a reference to an existing document of the right type).
  • Published slugs are unique per type.
  • Only editors publish and unpublish; only admins delete.
  • A revision is written in the publisher’s own name and never changes. A draft records its last editor, also only in the writer’s own name.

An invalid publish rolls back whole: the draft stays as it was and the document does not move.

A release is a named set of versions: for each document in it, the values to publish. Publishing a release writes every version as the next revision of its document, in one transaction. Readers see either none of it or all of it.

When a version is added, it records the revision its document was at. If that document is published on its own before the release goes out, the release is refused until the version is added again from the newer revision. A release never overwrites work published after it was put together.

A release publishes once. Two editors pressing Publish now at the same moment: one publishes, the other is told it already went out.

Editors schedule a release, or from the review sheet a single document, for a date and time. The CMS keeps a list of scheduled releases from the changes to cmsRelease, and the Worker’s cron ("triggers": { "crons": ["* * * * *"] }, which tapedb add writes) publishes what is due each minute.

A scheduled publish acts as the editor who scheduled it. Their role is checked at that moment, and the revisions carry their name. If the release can no longer publish cleanly (a document moved, a value became invalid, the editor lost their role), it is unscheduled and carries scheduleError with the reason, which the studio shows on the release.

Outside production, POST /_cms/tick with { "now": <epoch ms> } runs the same pass on demand, as if the time were now. It answers only when ENVIRONMENT is not "production".

The studio is one client of these rules. A script, a migration job or your own admin UI uses the same operations through createCms, with a TapeDB client that holds the person’s claim:

import { createCms } from "@tapedb/cms/client";
import { content } from "./cms.content";
const cms = createCms(db, content, { sub: user.id });
const id = await cms.create("post", { title: "Hello" });
await cms.edit("post", id, { body, slug: "hello", authorId });
await cms.publish("post", id, 0); // based on rev 0: publishes rev 1
await cms.draft("post", id); // a new draft from the published values
await cms.discard("post", id); // drop it
await cms.unpublish("post", id, 1); // based on rev 1
await cms.revisions("post", id); // every snapshot, oldest first
await cms.restore("post", id, 1); // revision 1's values into the draft
await cms.delete("post", id); // admins; refused while another document refers to it

Rich-text locks, for code that edits a field the studio may also be editing:

await cms.lock("post", id, "body"); // held for 30 seconds; take it again to renew
await cms.edit("post", id, { body });
await cms.unlock("post", id, "body");

Releases:

const release = await cms.releases.create("Spring issue");
await cms.releases.add(release, "post", id, { title: "Spring" }); // the version's values
await cms.releases.remove(release, "post", id);
await cms.releases.publish(release); // every version, one transaction
await cms.releases.schedule(release, Date.parse("2026-12-01T09:00:00Z"));
await cms.releases.unschedule(release);
await cms.releases.delete(release);

Each operation is one transaction. A refused write rejects with TapeDB’s permission_denied and leaves nothing behind.

The models are ordinary TapeDB models, so the client’s queries and live subscriptions work on them under the same rules. For example, a dashboard of everything waiting for review:

db.postDraft.findMany({ orderBy: { createdAt: "desc" } }).subscribe(({ data }) => render(data));

Readers (role user) see published documents only; contributors and up see drafts, revisions and versions.