Metadata Types
This page documents the content metadata types used in the ReX content system.
Core Metadata Interface
/**
* Base interface for content metadata
*/
interface ContentMetadata {
/**
* Human-readable title for the content
*/
title?: string
/**
* Brief description of the content
*/
description?: string
/**
* When the content was first created
*/
createdAt?: Date
/**
* When the content was last updated
*/
updatedAt?: Date
/**
* Optional array of content references
*/
references?: ContentReference[]
/**
* Extension point for custom metadata
*/
[key: string]: any
}
The ContentMetadata
interface provides a flexible structure for associating metadata with content. It includes common fields while allowing for custom metadata through its index signature.
Specialized Metadata Interfaces
The system defines several specialized metadata interfaces for specific content types:
Document Metadata
/**
* Metadata for document-like content (Markdown, HTML, etc.)
*/
interface DocumentMetadata extends ContentMetadata {
/**
* Document author
*/
author?: string
/**
* Publication date
*/
publishedAt?: Date
/**
* Tags or categories for the document
*/
tags?: string[]
/**
* Document language code (ISO 639-1)
*/
language?: string
/**
* Whether the document is in draft state
*/
draft?: boolean
}
Media Metadata
/**
* Metadata for image content
*/
interface ImageMetadata extends ContentMetadata {
/**
* Image width in pixels
*/
width?: number
/**
* Image height in pixels
*/
height?: number
/**
* Image format (png, jpeg, etc.)
*/
format?: string
/**
* Alternative text for accessibility
*/
alt?: string
/**
* Optional caption for the image
*/
caption?: string
}
/**
* Metadata for video content
*/
interface VideoMetadata extends ContentMetadata {
/**
* Video width in pixels
*/
width?: number
/**
* Video height in pixels
*/
height?: number
/**
* Video duration in seconds
*/
duration?: number
/**
* Video format (mp4, webm, etc.)
*/
format?: string
/**
* Optional thumbnail URI
*/
thumbnail?: string
/**
* Optional caption for the video
*/
caption?: string
}
Data Metadata
/**
* Metadata for data content (JSON, etc.)
*/
interface DataMetadata extends ContentMetadata {
/**
* Optional schema identifier
*/
schema?: string
/**
* Schema version
*/
schemaVersion?: string
/**
* Last validation timestamp
*/
validatedAt?: Date
/**
* Whether the data is valid according to its schema
*/
isValid?: boolean
}
Versioning Metadata
/**
* Metadata for content with versioning information
*/
interface VersionedMetadata extends ContentMetadata {
/**
* Content version identifier
*/
version?: string
/**
* Previous version identifier
*/
previousVersion?: string
/**
* Whether this is a published version
*/
published?: boolean
/**
* Optional version name or label
*/
versionLabel?: string
/**
* Optional version notes
*/
versionNotes?: string
}
Collaboration Metadata
/**
* Information about a content contributor
*/
interface Contributor {
/**
* Contributor identifier
*/
id: string
/**
* Contributor name
*/
name: string
/**
* Contributor email
*/
email?: string
/**
* Timestamp of contribution
*/
timestamp: Date
}
/**
* Metadata for collaborative content
*/
interface CollaborativeMetadata extends ContentMetadata {
/**
* Primary content author
*/
author?: Contributor
/**
* List of contributors
*/
contributors?: Contributor[]
/**
* List of editors
*/
editors?: Contributor[]
/**
* Last editor
*/
lastEditedBy?: Contributor
/**
* Vector clock for distributed collaboration
*/
vectorClock?: Record<string, number>
}
Content Reference Metadata
/**
* Types of content references
*/
type ContentReferenceType = 'embed' | 'link' | 'dependency'
/**
* Represents a reference to another content item
*/
interface ContentReference {
/**
* URI of the referenced content
*/
uri: string
/**
* Type of reference
*/
type: ContentReferenceType
/**
* Optional title for the reference
*/
title?: string
/**
* Optional description of the reference
*/
description?: string
}
Usage Examples
Basic Metadata
// Basic metadata for a blog post
const basicMetadata: ContentMetadata = {
title: 'Getting Started with ReX',
description: 'A guide to using the content system',
createdAt: new Date('2025-04-28T12:00:00Z'),
updatedAt: new Date('2025-05-02T09:30:00Z'),
}
Document Metadata
// Rich metadata for a document
const documentMetadata: DocumentMetadata = {
title: 'Advanced Composition Patterns',
description: 'Learn advanced function composition techniques',
author: 'Jane Smith',
publishedAt: new Date('2025-04-30T00:00:00Z'),
tags: ['functional-programming', 'composition', 'typescript'],
language: 'en',
draft: false,
createdAt: new Date('2025-04-15T10:00:00Z'),
updatedAt: new Date('2025-04-29T16:45:00Z'),
}
Media Metadata
// Metadata for an image
const imageMetadata: ImageMetadata = {
title: 'System Architecture Diagram',
width: 1200,
height: 800,
format: 'png',
alt: 'Diagram showing the layered architecture of ReX',
caption: 'Figure 1: Layered architecture with content facade',
createdAt: new Date('2025-04-20T14:30:00Z'),
}
Versioned Content
// Metadata for versioned content
const versionedMetadata: VersionedMetadata = {
title: 'API Documentation',
version: '1.2.0',
previousVersion: '1.1.0',
published: true,
versionLabel: 'April 2025 Release',
versionNotes: 'Added documentation for new middleware features',
createdAt: new Date('2025-01-15T00:00:00Z'),
updatedAt: new Date('2025-04-25T17:00:00Z'),
}
Collaborative Content
// Metadata for collaborative content
const collaborativeMetadata: CollaborativeMetadata = {
title: 'Project Roadmap',
author: {
id: 'user-123',
name: 'Alex Johnson',
email: '[email protected]',
timestamp: new Date('2025-03-10T09:00:00Z'),
},
contributors: [
{
id: 'user-456',
name: 'Sam Wilson',
email: '[email protected]',
timestamp: new Date('2025-04-12T11:30:00Z'),
},
{
id: 'user-789',
name: 'Taylor Kim',
email: '[email protected]',
timestamp: new Date('2025-04-15T14:45:00Z'),
},
],
lastEditedBy: {
id: 'user-456',
name: 'Sam Wilson',
email: '[email protected]',
timestamp: new Date('2025-04-23T16:20:00Z'),
},
vectorClock: {
'user-123': 3,
'user-456': 7,
'user-789': 2,
},
createdAt: new Date('2025-03-10T09:00:00Z'),
updatedAt: new Date('2025-04-23T16:20:00Z'),
}
Metadata Extraction
The system provides utilities for extracting metadata from different content types:
import { extractMetadata } from '@lib/content/processors'
// Extract metadata from Markdown frontmatter
const markdownContent = `---
title: Getting Started
author: John Doe
tags: [tutorial, beginner]
---
# Getting Started
Welcome to the tutorial!`
const metadata = extractMetadata(markdownContent, 'text/markdown')
// Returns: { title: 'Getting Started', author: 'John Doe', tags: ['tutorial', 'beginner'] }
Best Practices
When working with metadata:
Type Extensions: Extend the base interface for type safety:
typescriptinterface BlogPostMetadata extends ContentMetadata { author: string publishDate: Date tags: string[] featured?: boolean } const post: Content<string> & { metadata: BlogPostMetadata } = { data: '# My Blog Post\n\nContent here', contentType: 'text/markdown', metadata: { title: 'My Blog Post', author: 'Jane Smith', publishDate: new Date(), tags: ['news', 'technology'], }, }
Date Handling: Always use full Date objects, not strings, for date fields
Metadata Validation: Validate metadata against schemas for consistency
Minimal Metadata: Only include relevant metadata for your content type
References: Use the references field to track content relationships