Core Concepts

This page explains the fundamental concepts of the registry system.

Registry schemas use the provider-neutral StandardSchemaV1 contract. The examples can be authored with Zod Mini, Zod, Valibot, Effect Schema, or another Standard Schema implementation.

createRegistry

Builds a read-only registry from a list. The forms engine uses it for elements, recipes, actions and validation rules, and ActionRegistry is built on it. ValidationRegistry in @schema-engine/forms is a read-only registry of this kind with a few validation lookups added.

function createRegistry<TRegistration extends BaseRegistration>(
	kind: string,
	registrations: readonly TRegistration[],
): ReadOnlyRegistry<TRegistration>;

interface ReadOnlyRegistry<TRegistration extends BaseRegistration> {
	readonly kind: string;
	readonly size: number;
	get(key: string): TRegistration | undefined;
	has(key: string): boolean;
	all(): readonly TRegistration[];
	keys(): readonly string[];
}
BehaviorDescription
Last winsA later registration with the same $type replaces the earlier one, with no warning.
Checked at buildA winning schema without ~standard.validate throws, naming the kind and the registration's $type.
FrozenNo register or clear. The registry, its arrays and its stored copies are frozen. Your objects are untouched.

BaseRegistry (mutable opt-in)

The abstract base class for plugin systems that register at runtime. Prefer createRegistry unless you need register after construction.

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

MethodDescription
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
sizeNumber of registered items
clear()Removes all items (useful for testing)

See Registries and the catalog for what the forms engine registers and how to add a kind of your own.

Renderable registrations

Use a ComponentRegistration type with createRegistry, or with BaseRegistry<string, WidgetRegistration>, when values must include a render function. The removed ComponentRegistry class added no runtime behavior.

BaseRegistration

The interface that all registry items must implement:

interface BaseRegistration<TConfig = unknown, TMeta extends ComponentMetadata = ComponentMetadata> {
	$type: string;
	schema: StandardSchemaV1<TConfig>;
	metadata: TMeta;
}

$type is the stable registry key, schema describes the configuration contract, and metadata carries human-readable information.

ComponentRegistration

Extended interface for renderable components:

interface ComponentRegistration<
	TType extends string = string,
	TConfig = unknown,
	TProps = unknown,
	TMeta extends ComponentMetadata = ComponentMetadata,
> extends BaseRegistration<TConfig, TMeta> {
	$type: TType;
	render: (props: TProps) => unknown;
}

ComponentMetadata

Standard metadata for all components:

interface ComponentMetadata {
	name: string;
	description?: string;
	icon?: string;
	tags?: string[];
	version?: string;
}