@bernierllc/content-type-text
v1.2.0
Published
Bare bones text content type with TipTap WYSIWYG editor and markdown file storage
Readme
@bernierllc/content-type-text
Bare bones text content type with TipTap WYSIWYG editor and markdown file storage.
Installation
npm install @bernierllc/content-type-textOverview
This package provides a minimal, foundational text content type designed to be extended by specialized content types (blog posts, tweets, commit messages, etc.). It includes:
- Bare bones TipTap WYSIWYG editor with starter-kit only
- Markdown file storage with basic frontmatter (content, createdAt, updatedAt)
- Content type registration with @bernierllc/content-type-registry
- Simple, extensible API for custom text types
Features
- ✅ Minimal TipTap editor configuration
- ✅ Markdown file storage with frontmatter
- ✅ Content validation with Zod
- ✅ TypeScript with strict mode
- ✅ 90%+ test coverage
- ✅ Zero dependencies (except TipTap, Zod, gray-matter)
Usage
Basic Usage
import { TextContentType, createTextContentType } from '@bernierllc/content-type-text';
// Create instance
const textType = createTextContentType({
id: 'text',
name: 'Text',
storageDirectory: './content',
});
// Create content
const result = await textType.create('Hello, world!');
console.log(result.data); // File path: ./content/1234567890-hello-world.md
// Read content
const readResult = await textType.read(result.data!);
console.log(readResult.data?.content); // "Hello, world!"
// Update content
await textType.update(result.data!, 'Updated content');
// Delete content
await textType.delete(result.data!);Register with Content Type Registry
import { ContentTypeRegistry } from '@bernierllc/content-type-registry';
import { TextContentType } from '@bernierllc/content-type-text';
const registry = new ContentTypeRegistry();
const textType = new TextContentType();
await textType.register(registry);Using TipTap Editor
import { createTipTapEditor, getMarkdownFromEditor, destroyEditor } from '@bernierllc/content-type-text';
// Create editor (requires DOM environment)
const editor = createTipTapEditor({
content: 'Initial content',
editable: true,
});
// Get content
const markdown = getMarkdownFromEditor(editor);
// Clean up
destroyEditor(editor);Extending for Custom Types
import { TextContentType } from '@bernierllc/content-type-text';
class BlogPostType extends TextContentType {
constructor() {
super({
id: 'blog-post',
name: 'Blog Post',
storageDirectory: './blog-posts',
});
}
// Add custom methods
async addMetadata(filePath: string, metadata: any) {
// Custom implementation
}
}API
TextContentType
Main class for text content management.
Constructor
new TextContentType(config?: TextContentTypeConfig)Config Options:
id(string, default: 'text') - Content type identifiername(string, default: 'Text') - Content type display namestorageDirectory(string, default: './content') - Storage directory path
Methods
register(registry: ContentTypeRegistry): Promise<TextContentResult<void>>
Register this content type with the registry.
create(content: string): Promise<TextContentResult<string>>
Create new text content. Returns file path on success.
read(filePath: string): Promise<TextContentResult<TextContentMetadata>>
Read text content from file.
update(filePath: string, content: string): Promise<TextContentResult<void>>
Update existing text content.
delete(filePath: string): Promise<TextContentResult<void>>
Delete text content file.
validate(data: unknown): TextContentResult<TextContentMetadata>
Validate text content metadata.
Types
TextContentMetadata
interface TextContentMetadata {
content: string;
createdAt: Date;
updatedAt: Date;
}TextContentResult
interface TextContentResult<T = unknown> {
success: boolean;
data?: T;
error?: string;
}TipTapEditorConfig
interface TipTapEditorConfig {
content?: string;
editable?: boolean;
}Storage Format
Content is stored as markdown files with YAML frontmatter:
---
createdAt: '2025-01-01T00:00:00.000Z'
updatedAt: '2025-01-02T00:00:00.000Z'
---
Your content here...Filenames are generated as: {timestamp}-{sanitized-content}.md
Examples
Complete CRUD Operations
import { createTextContentType } from '@bernierllc/content-type-text';
const textType = createTextContentType({ storageDirectory: './my-content' });
// Create
const createResult = await textType.create('My first post');
const filePath = createResult.data!;
// Read
const readResult = await textType.read(filePath);
console.log(readResult.data?.content); // "My first post"
console.log(readResult.data?.createdAt); // Date object
// Update
await textType.update(filePath, 'My updated post');
// Read again
const updatedResult = await textType.read(filePath);
console.log(updatedResult.data?.content); // "My updated post"
// Delete
await textType.delete(filePath);Error Handling
const result = await textType.read('/non/existent/file.md');
if (!result.success) {
console.error('Error:', result.error);
} else {
console.log('Content:', result.data?.content);
}Validation
const validationResult = textType.validate({
content: 'Valid content',
createdAt: new Date(),
updatedAt: new Date(),
});
if (validationResult.success) {
console.log('Valid:', validationResult.data);
} else {
console.error('Invalid:', validationResult.error);
}Integration Status
- Logger: not-applicable - Base content type has no side effects requiring logging
- Docs-Suite: ready - TypeScript types and documentation exported
- NeverHub: not-applicable - Core type definition with no service mesh participation
Development
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Build package
npm run build
# Lint code
npm run lintLicense
Copyright (c) 2025 Bernier LLC
This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
Related Packages
- @bernierllc/content-type-registry - Content type registration and discovery
- @bernierllc/content-type-blog-post - Blog post type extending text (planned)
- @bernierllc/content-type-tweet - Twitter post type extending text (planned)
- @bernierllc/content-type-commit - Git commit type extending text (planned)
Integration Status
Logger Integration
- Status: not-applicable
- Justification: Core content type package with standard error handling. File operations use try/catch patterns.
NeverHub Integration
- Status: not-applicable
- Justification: Core package providing content type definition. Services and suites that USE this package will handle NeverHub integration for content management events.
Docs-Suite Compatibility
- Status: ready
- Format: typedoc
- Documentation: Complete API documentation with TypeScript types
