
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, context files, and provider contracts (enabling third-party RepoProvider implementations).
Use @contentrain/types when you are:
RepoProvider for a new git backendpnpm add @contentrain/types
Core unions:
FieldTypeModelKindContentStatusContentSourceWorkflowModeStackTypePlatformContextSourceCollectionRuntimeFormatLocaleStrategyCore interfaces:
FieldDefModelDefinitionModelSummaryContentrainConfigVocabularyEntryMetaAssetEntryValidationErrorValidationResultScaffoldTemplateScanCandidateDuplicateGroupGraphNodeProjectGraphScanCandidatesResultScanSummaryResultContextJsonStorage/runtime helper types:
SingletonContentFileCollectionContentFileDictionaryContentFileCollectionEntryCollectionContentOutputDocumentEntryDocumentContentOutputSingletonMetaCollectionMetaDocumentMetaDictionaryMetaNormalize/plan types:
NormalizePlanNormalizePlanModelNormalizePlanExtractionNormalizePlanPatchProvider contracts (re-exported from provider.ts — implement these to add a new git backend):
RepoProviderRepoReaderRepoWriterProviderCapabilitiesFileChangeCommitAuthorCommitApplyPlanInputBranchFileDiffMergeResult (includes optional sync?: SyncResult for local-worktree providers)LOCAL_CAPABILITIES (const — capability set for LocalProvider)Git transaction types:
SyncResultContentrainErrorValidate 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 frontmatterConstants:
CONTENTRAIN_DIR — default .contentrain folder nameCONTENTRAIN_BRANCH — default contentrain branch name for content trackingPATH_PATTERNS — file path conventions for models, content, metaSLUG_PATTERN — regex for valid slugsENTRY_ID_PATTERN — regex for valid entry IDsLOCALE_PATTERN — regex for valid locale codesCANONICAL_JSON — serialization rules (indent, encoding, trailing newline, key sort)SECRET_PATTERNS — regex patterns for secret detectionThis package is intended to be the shared public contract across the Contentrain ecosystem.
In practice that means:
RepoProvider contract enables third-party implementations without depending on @contentrain/mcp internalsimport 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'
Provider contract usage (for custom RepoProvider implementations):
import type { RepoProvider, ProviderCapabilities } from '@contentrain/types'
export class MyCustomProvider implements RepoProvider {
readonly capabilities: ProviderCapabilities = {
localWorktree: false,
sourceRead: true,
sourceWrite: true,
pushRemote: true,
branchProtection: true,
pullRequestFallback: true,
astScan: false,
}
// ...implement RepoProvider methods
}
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:pathvalidateFieldValue 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 FieldDefRepoProvider to plug into MCPThis 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
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.