API Reference
Complete API documentation for @schema-engine/registry.
BaseRegistry
Abstract class for all registries.
abstract class BaseRegistry<TKey extends string, TValue extends BaseRegistration> {
protected items: Map<TKey, TValue>;
abstract get registryName(): string;
protected getItemKey(item: TValue): TKey;
protected getItemName(item: TValue): string;
register(item: TValue): void;
has(key: TKey): boolean;
get(key: TKey): TValue | undefined;
getAll(): TValue[];
getAllKeys(): TKey[];
get size(): number;
clear(): void;
getMap(): Map<TKey, TValue>;
registerSchemas(
zodRegistry: ReturnType<typeof z.registry>,
metadataBuilder: (item: TValue) => Record<string, unknown>
): void;
}Methods
| Method | Returns | Description |
|---|---|---|
register(item) | void | Registers an item. Logs warning on override. |
has(key) | boolean | Checks if key exists |
get(key) | TValue | undefined | Gets item by key |
getAll() | TValue[] | Returns all items |
getAllKeys() | TKey[] | Returns all keys |
size | number | Count of items |
clear() | void | Removes all items |
getMap() | Map | Returns internal map (use sparingly) |
registerSchemas(zodRegistry, metadataBuilder) | void | Registers all schemas to a Zod registry |
Protected Methods
| Method | Description |
|---|---|
getItemKey(item) | Extracts key from item (uses $type) |
getItemName(item) | Extracts name from item (uses metadata.name) |
ComponentRegistry
Abstract class for component registries. Extends BaseRegistry.
abstract class ComponentRegistry<
TKey extends string,
TValue extends ComponentRegistration<any, any, any>
> extends BaseRegistry<TKey, TValue> {
// Inherits all BaseRegistry methods
// Specialized component behavior can be added here in the future.
// For now, it provides stronger type safety for renderable items.
}Types
BaseRegistration
interface BaseRegistration<TConfig = unknown, TMeta extends ComponentMetadata = ComponentMetadata> {
$type: string;
schema: z.ZodType<TConfig>;
metadata: TMeta;
}ComponentRegistration
interface ComponentRegistration<
TType extends string = string,
TConfig = unknown,
TProps = unknown,
TMeta extends ComponentMetadata = ComponentMetadata
> extends BaseRegistration<TConfig, TMeta> {
/** Framework-agnostic render function */
render: (props: TProps) => unknown;
/** Type identifier - enforced to match registry key */
$type: TType;
}ComponentMetadata
interface ComponentMetadata {
name: string;
description?: string;
icon?: string;
tags?: string[];
version?: string;
}Brand
Utility type for compile-time type discrimination (erased at runtime):
type Brand<T, TBrand> = T & { readonly [__brand]?: TBrand };