
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@contentrain/types
Advanced tools
@contentrain/typesShared TypeScript types for the Contentrain ecosystem.
Start here:
This package is the common schema layer used by:
@contentrain/mcpcontentrain@contentrain/query@contentrain/rulesIt defines the stable type vocabulary for models, config, metadata, validation, scanning, and context files.
Use @contentrain/types when you are:
pnpm add @contentrain/types
Core unions:
FieldTypeModelKindContentStatusContentSourceWorkflowModeStackTypePlatformContextSourceCollectionRuntimeFormatLocaleStrategyCore interfaces:
FieldDefModelDefinitionContentrainConfigVocabularyEntryMetaAssetEntryValidationErrorValidationResultScaffoldTemplateScanCandidateDuplicateGroupGraphNodeProjectGraphScanCandidatesResultScanSummaryResultContextJsonStorage/runtime helper types:
SingletonContentFileCollectionContentFileDictionaryContentFileCollectionEntryCollectionContentOutputSingletonMetaCollectionMetaDocumentMetaDictionaryMetaValidate functions (pure, dependency-free):
validateSlug(slug) — kebab-case slug validationvalidateEntryId(id) — entry ID format validationvalidateLocale(locale, config) — locale format + config support checkdetectSecrets(value) — detect potential secrets in field valuesvalidateFieldValue(value, fieldDef) — full field schema validation (type, required, min/max, pattern, select)Serialize functions (pure, dependency-free):
sortKeys(obj, fieldOrder?) — recursive key sorting for canonical outputcanonicalStringify(data, fieldOrder?) — deterministic JSON serializationgenerateEntryId() — 12-char hex ID generationparseMarkdownFrontmatter(content) — parse YAML frontmatter + body from markdownserializeMarkdownFrontmatter(data, body) — serialize data + body into markdown frontmatterThis package is intended to be the shared public contract across the Contentrain ecosystem.
In practice that means:
import type {
ContentrainConfig,
FieldDef,
ModelDefinition,
ValidationResult,
} from '@contentrain/types'
const fields: Record<string, FieldDef> = {
title: { type: 'string', required: true },
slug: { type: 'slug', required: true, unique: true },
}
const model: ModelDefinition = {
id: 'blog-post',
name: 'Blog Post',
kind: 'collection',
domain: 'blog',
i18n: true,
fields,
}
const config: ContentrainConfig = {
version: 1,
stack: 'next',
workflow: 'review',
locales: { default: 'en', supported: ['en', 'tr'] },
domains: ['blog'],
}
const result: ValidationResult = {
valid: true,
errors: [],
}
Type-only usage:
import type { ModelDefinition, ContentrainConfig } from '@contentrain/types'
Mixed usage (types + runtime functions):
import type { FieldDef, ValidationError } from '@contentrain/types'
import {
validateFieldValue,
validateSlug,
detectSecrets,
canonicalStringify,
parseMarkdownFrontmatter,
} from '@contentrain/types'
Studio (Nuxt 4, web) cannot import @contentrain/mcp directly because MCP depends on Node.js-only packages (simple-git, @modelcontextprotocol/sdk). The validate and serialize functions in this package are pure, dependency-free, and browser-compatible — designed for Studio to share the same validation contract as MCP.
@contentrain/types| Function | Use case |
|---|---|
validateSlug(slug) | Form validation for document slugs |
validateEntryId(id) | Validate collection entry IDs |
validateLocale(locale, config) | Locale picker validation |
detectSecrets(value) | Content editor secret detection warnings |
validateFieldValue(value, fieldDef) | Full field-level validation in content forms |
canonicalStringify(data, fieldOrder?) | Preview canonical JSON output |
parseMarkdownFrontmatter(content) | Document editor frontmatter parsing |
serializeMarkdownFrontmatter(data, body) | Document editor serialization |
generateEntryId() | Client-side entry ID generation |
SECRET_PATTERNS | Extend or customize secret detection |
These require file system I/O or Node.js dependencies:
checkRelation() — validates relation references against actual content files on diskvalidateProject() — full project validation with file readingwriteContent() / deleteContent() — content persistence with git worktreeresolveContentDir() / resolveJsonFilePath() — path resolution with node:path// composables/useContentValidation.ts
import type { FieldDef, ContentrainConfig, ValidationError } from '@contentrain/types'
import { validateFieldValue, validateSlug, detectSecrets } from '@contentrain/types'
export function useContentValidation(config: ContentrainConfig) {
function validateEntry(
fields: Record<string, FieldDef>,
data: Record<string, unknown>,
): ValidationError[] {
const issues: ValidationError[] = []
for (const [fieldName, fieldDef] of Object.entries(fields)) {
// Schema validation (type, required, min/max, pattern, select)
const fieldErrors = validateFieldValue(data[fieldName], fieldDef)
for (const err of fieldErrors) {
issues.push({ ...err, field: fieldName })
}
// Secret detection on all string values
const secretErrors = detectSecrets(data[fieldName])
for (const err of secretErrors) {
issues.push({ ...err, field: fieldName })
}
}
return issues
}
return { validateEntry, validateSlug }
}
// composables/useDocumentEditor.ts
import { parseMarkdownFrontmatter, serializeMarkdownFrontmatter } from '@contentrain/types'
export function useDocumentEditor() {
function loadDocument(rawMarkdown: string) {
const { frontmatter, body } = parseMarkdownFrontmatter(rawMarkdown)
return { frontmatter, body }
}
function saveDocument(data: Record<string, unknown>, body: string): string {
return serializeMarkdownFrontmatter(data, body)
}
return { loadDocument, saveDocument }
}
validateFieldValue handles schema-level checks. Two things require external state:
These are left to Studio's server-side or API layer to implement on top of the pure validation.
@contentrain/types exists so every package in the monorepo speaks the same domain language.
Examples:
ModelDefinitionContextJsonModelDefinition and FieldDefThis package should stay:
From the monorepo root:
pnpm --filter @contentrain/types build
pnpm --filter @contentrain/types test
pnpm --filter @contentrain/types typecheck
@contentrain/mcpcontentrain@contentrain/query@contentrain/rulesMIT
FAQs
Shared TypeScript types for Contentrain ecosystem
The npm package @contentrain/types receives a total of 64 weekly downloads. As such, @contentrain/types popularity was classified as not popular.
We found that @contentrain/types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.