@cimi-cms/schema
v0.1.0-beta.0
Published
Code-first, type-safe content schemas for CIMI — define blocks, sections and content types in TypeScript and infer their data types.
Maintainers
Readme
@cimi-cms/schema
Code-first, type-safe content schemas for CIMI. Define blocks, sections
and content types in TypeScript — the data types are inferred from the definitions, no
codegen step, and the same definitions serialize to the schema format that
GET /api/v1/apps/{appId}/schema serves and cimi push applies.
npm install @cimi-cms/schemaDefine
import { defineBlock, defineField, defineSchema } from '@cimi-cms/schema';
export const heroBlock = defineBlock({
key: 'home-hero',
label: 'Home hero',
fields: {
title: defineField({ type: 'text', label: 'Titel', required: true, localized: true }),
theme: defineField({ type: 'select', label: 'Thema', options: ['light', 'dark'] }),
'primary-link': defineField({ type: 'url', label: 'Primaire link' }),
},
});
export const schema = defineSchema({
locales: ['nl', 'en'],
defaultLocale: 'nl',
blocks: [heroBlock],
});Infer
import type { BlockData, InferSchemaTypes } from '@cimi-cms/schema';
type HeroData = BlockData<typeof heroBlock>;
// { title: string; theme: 'light' | 'dark' | null; 'primary-link': LinkValue | null }
type MyCimi = InferSchemaTypes<typeof schema>;
// The type argument for the @cimi-cms/sdk v2 client: new CimiClient<MyCimi>(…)Sync
Pushing, pulling and diffing schemas against a live CIMI app is the job of
@cimi-cms/cli:
npx cimi diff # local definitions vs the live app
npx cimi push --dry-run
npx cimi pushRenames are explicit, never guessed: give the new definition a renamedFrom: 'old-key' hint
and cimi push migrates the stored content along with the key. See the repository's
docs/SCHEMA_AS_CODE.md for the full model (managed mode, hashing, validation).
Also in this package
toNormalizedSchema(schema)— definitions → normalized wire schemadiffSchemas(current, desired)— the structural differ used by both the CLI and the servercomputeSchemaHash(body)— from the@cimi-cms/schema/hashsubpath (Node-only)- The normalized value shapes (
LinkValue,MediaValue,RelationValue,BlockValue) shared with@cimi-cms/sdk
MIT © Wouters Media
