@arche-cms/schema
v0.1.5
Published
Schema definition API for Arche CMS. Define collections, globals, and components using a declarative field system.
Readme
@arche-cms/schema
Schema definition API for Arche CMS. Define collections, globals, and components using a declarative field system.
Installation
yarn add @arche-cms/schemaUsage
Define a Collection
import { defineCollection, text, slug, richText, select, relation } from "@arche-cms/schema";
export default defineCollection({
slug: "posts",
labels: { singular: "Post", plural: "Posts" },
fields: [
text("title", { required: true }),
slug("slug", { from: "title" }),
richText("content"),
select("status", { options: ["draft", "published", "archived"] }),
relation("author", { to: "users" }),
],
});Define a Global
import { defineGlobal, text, media } from "@arche-cms/schema";
export default defineGlobal({
slug: "site-settings",
label: "Site Settings",
fields: [text("siteName"), media("logo")],
});Define a Component
import { defineComponent, text, url } from "@arche-cms/schema";
export default defineComponent({
slug: "cta-block",
label: "Call to Action",
fields: [text("heading"), text("buttonLabel"), url("buttonUrl")],
});Schema Loader
Load schema files from the filesystem:
import { SchemaLoader } from "@arche-cms/schema";
const loader = new SchemaLoader({ baseDir: "./cms" });
const schemas = await loader.load();
// schemas.collections, schemas.globals, schemas.componentsSchema Validator
Validate collection definitions at runtime:
import { validateCollection } from "@arche-cms/schema";
const result = validateCollection(collectionDef);
if (!result.valid) {
console.error(result.issues);
}Field Types
text, textarea, number, boolean, date, datetime, email, password, url, json, richText, markdown, code, color, media, upload, select, multiSelect, radio, checkbox, relation, component, dynamicZone, array, object, tabs, group, repeater, slug
