npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bernierllc/content-type-registry

v1.0.4

Published

Central registry for content type discovery, registration, and validation with Zod schemas

Readme

@bernierllc/content-type-registry

Central registry for content type discovery, registration, and validation with Zod schemas.

Installation

npm install @bernierllc/content-type-registry

Usage

import { ContentTypeRegistry, BaseContentType } from '@bernierllc/content-type-registry';
import { z } from 'zod';

// Create a registry instance
const registry = new ContentTypeRegistry();

// Register a content type
const result = registry.register({
  id: 'blog-post',
  name: 'Blog Post',
  description: 'A long-form article',
  baseType: BaseContentType.TEXT,
  icon: 'document',
  schema: z.object({
    title: z.string().min(1).max(200),
    content: z.string(),
    publishedAt: z.date().optional()
  }),
  editor: {
    component: 'RichTextEditor',
    fields: [
      { name: 'title', label: 'Title', type: 'text', required: true },
      { name: 'content', label: 'Content', type: 'textarea', required: true }
    ]
  },
  storage: {
    method: 'database'
  },
  publishing: {
    methods: ['web', 'api'],
    defaultMethod: 'web'
  }
});

if (result.success) {
  console.log('Content type registered successfully');
}

// Retrieve a content type
const typeResult = registry.get('blog-post');
if (typeResult.success) {
  console.log('Retrieved type:', typeResult.data);
}

// List all content types
const listResult = registry.list();
if (listResult.success) {
  console.log('All types:', listResult.data);
}

// Filter content types
const textTypes = registry.list({ baseType: BaseContentType.TEXT });

// Validate content against a type's schema
const validateResult = registry.validate('blog-post', {
  title: 'My First Post',
  content: 'This is the content of my post'
});

if (validateResult.success) {
  console.log('Valid content:', validateResult.data);
} else {
  console.error('Validation failed:', validateResult.error);
}

API Reference

ContentTypeRegistry

The main registry class for managing content types.

register(definition: ContentTypeDefinition): RegistryResult<void>

Registers a new content type in the registry.

Parameters:

  • definition - Complete content type definition with schema, editor config, etc.

Returns: RegistryResult<void> - Success/failure result

unregister(typeId: string): RegistryResult<void>

Unregisters a content type from the registry.

Parameters:

  • typeId - ID of the type to unregister

Returns: RegistryResult<void> - Success/failure result

get(typeId: string): RegistryResult<ContentTypeDefinition>

Retrieves a specific content type definition.

Parameters:

  • typeId - ID of the type to retrieve

Returns: RegistryResult<ContentTypeDefinition> - The type definition or error

list(filter?: ContentTypeFilter): RegistryResult<ContentTypeDefinition[]>

Lists all registered content types with optional filtering.

Parameters:

  • filter - Optional filter criteria (baseType, ids, search, metadata)

Returns: RegistryResult<ContentTypeDefinition[]> - Array of matching types

getValidator(typeId: string): RegistryResult<z.ZodSchema>

Gets the Zod validator schema for a content type.

Parameters:

  • typeId - ID of the type

Returns: RegistryResult<z.ZodSchema> - The Zod schema for validation

getBaseType(typeId: string): RegistryResult<BaseContentType>

Gets the base type for a content type.

Parameters:

  • typeId - ID of the type

Returns: RegistryResult<BaseContentType> - The base type (TEXT, IMAGE, AUDIO, VIDEO)

listExtendedTypes(baseType: BaseContentType): RegistryResult<ContentTypeDefinition[]>

Lists all types that extend from a specific base type.

Parameters:

  • baseType - The base type to filter by

Returns: RegistryResult<ContentTypeDefinition[]> - Array of types extending the base type

validate(typeId: string, content: any): RegistryResult<any>

Validates content against a type's schema.

Parameters:

  • typeId - ID of the content type
  • content - Content to validate

Returns: RegistryResult<any> - Validated content or error

has(typeId: string): boolean

Checks if a type is registered.

Parameters:

  • typeId - ID of the type to check

Returns: boolean - True if registered, false otherwise

count(): number

Returns the number of registered types.

Returns: number - Count of registered types

clear(): void

Clears all registered types (useful for testing).

Base Content Types

enum BaseContentType {
  TEXT = 'text',
  IMAGE = 'image',
  AUDIO = 'audio',
  VIDEO = 'video'
}

Types

All type definitions are exported for TypeScript users:

  • ContentTypeDefinition - Complete type definition
  • ContentTypeFilter - Filter criteria for listing
  • RegistryResult<T> - Standard result type
  • FieldConfig - Editor field configuration
  • EditorConfig - Editor configuration
  • StorageConfig - Storage configuration
  • PublishingConfig - Publishing configuration
  • WorkflowTemplate - Workflow template definition
  • WorkflowStep - Individual workflow step

Singleton Instance

A singleton registry instance is exported for convenience:

import { contentTypeRegistry } from '@bernierllc/content-type-registry';

contentTypeRegistry.register(myType);

Integration Status

  • Logger: not-applicable - Pure registry package with no I/O operations requiring @bernierllc/logger integration
  • Docs-Suite: ready - Complete TypeDoc API documentation
  • NeverHub: optional - Can publish registration events for observability using @bernierllc/neverhub-adapter with detectNeverHub()

License

Copyright (c) 2025 Bernier LLC. All rights reserved.