@velora-cms/content-service
v0.14.0
Published
Immutable content versioning service for Velora CMS
Readme
@velora-cms/content-service
The content versioning engine at the core of Velora CMS:
every save is an insert, never an update, so nothing is ever silently
overwritten. This package implements that rule on top of
@velora-cms/db-adapter and is what @velora-cms/server runs on for
every content read and write.
npm install @velora-cms/content-serviceWho this is for
If you're building a Velora site, you don't need this package — talk to
a running server through @velora-cms/client instead. content-service
is for people extending the server itself, or building tooling that
needs to drive content versioning directly against a DatabaseAdapter
(a custom import pipeline, a migration script, a test harness).
What's in it
ContentService — create, save, and publish content, always by inserting
a new ContentVersion row rather than mutating one:
import { ContentService } from "@velora-cms/content-service";
import { PostgreSQLAdapter } from "@velora-cms/db-adapter";
const adapter = new PostgreSQLAdapter();
await adapter.connect({ connectionString: process.env.DATABASE_URL });
const content = new ContentService(adapter);
// createContent inserts the node AND its first ContentVersion (version 1).
const { node, version } = await content.createContent({
documentTypeId: "...",
parentId: null,
path: "/hello-world",
depth: 0,
sortOrder: 0,
locale: "en",
isDefaultLocale: true,
data: { title: "Hello, world" },
createdBy: "user-id",
});
// saveContent NEVER updates the row above — it always inserts version 2,
// 3, 4... and leaves node.currentVersion pointing wherever it was.
await content.saveContent(node.id, { title: "Hello, world (edited)" }, "user-id");Also exported: DocumentTypeService (define and manage document types,
refusing to delete a type still referenced by content) and
SnapshotService (point-in-time content snapshots), plus the field
validation helpers (validateField, validateFieldsAgainstDocumentType)
and error types (ContentValidationError, TreeRulesViolationError, and
others) that createContent/saveContent throw.
Relationship to the rest of Velora
content-service depends on @velora-cms/api-schemas for its types and
@velora-cms/db-adapter for storage — it never issues raw SQL itself,
the same rule plugins follow. @velora-cms/server is its only real
consumer today; it wires ContentService up to the public and admin
HTTP routes. If you want content over HTTP rather than this in-process
API, use @velora-cms/client or the REST/GraphQL API directly.
Source & support
Source: velora-starter. Docs: https://docs.velora-cms.com. Apache-2.0.
