Core Concepts
This page explains the fundamental concepts of the registry system.
BaseRegistry
The abstract base class that provides common registration, retrieval, and management functionality. All registries in the schema-engine ecosystem extend this class.
import { BaseRegistry } from '@schema-engine/registry';
import type { BaseRegistration } from '@schema-engine/registry';
abstract class BaseRegistry<TKey extends string, TValue extends BaseRegistration> {
protected items: Map<TKey, TValue>;
abstract get registryName(): string;
register(item: TValue): void;
has(key: TKey): boolean;
get(key: TKey): TValue | undefined;
getAll(): TValue[];
getAllKeys(): TKey[];
get size(): number;
clear(): void;
}Key Methods
| Method | Description |
|---|---|
register(item) | Adds an item to the registry. Logs a warning if overriding. |
has(key) | Checks if an item exists |
get(key) | Retrieves an item by key |
getAll() | Returns all registered items |
getAllKeys() | Returns all registered keys |
size | Number of registered items |
clear() | Removes all items (useful for testing) |
ComponentRegistry
A specialized registry for visual components that require a render method. Elements, layouts, and steppers use this.
import { ComponentRegistry } from '@schema-engine/registry';
import type { ComponentRegistration } from '@schema-engine/registry';
abstract class ComponentRegistry<
TKey extends string,
TValue extends ComponentRegistration
> extends BaseRegistry<TKey, TValue> {
// Inherits all BaseRegistry methods
// Enforces that items have a render() method
}BaseRegistration
The interface that all registry items must implement:
interface BaseRegistration<TConfig = unknown, TMeta extends ComponentMetadata = ComponentMetadata> {
$type: string; // Unique identifier within the registry
schema: z.ZodType<TConfig>; // Zod schema for validation
metadata: TMeta; // Component metadata
}ComponentRegistration
Extended interface for renderable components:
interface ComponentRegistration<
TType extends string,
TConfig,
TProps,
TMeta extends ComponentMetadata
> extends BaseRegistration<TConfig, TMeta> {
$type: TType;
render: (props: TProps) => unknown;
}ComponentMetadata
Standard metadata for all components:
interface ComponentMetadata {
name: string; // Human-readable display name
description?: string; // Detailed description
icon?: string; // Icon identifier for UI
tags?: string[]; // Tags for filtering
version?: string; // Component version
}