API Reference

Complete API documentation for @schema-engine/registry.

createRegistry

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

Builds a frozen, read-only registry. A later registration with the same $type replaces an earlier one without a warning and keeps its first position. Throws <kind> '<$type>' schema must implement Standard Schema (~standard.validate). when a winning registration's schema is not a Standard Schema; an overridden registration is not checked. The registry stores a frozen shallow copy of each winner and leaves the objects you passed untouched.

ReadOnlyRegistry

MemberReturnsDescription
kindstringThe label passed to createRegistry
sizenumberCount of distinct $type keys
get(key)TRegistration | undefinedGets a registration by $type
has(key)booleanChecks if the key exists
all()readonly TRegistration[]Frozen array in first-registration order
keys()readonly string[]Frozen array of keys in the same order

assertStandardSchema

function assertStandardSchema(schema: unknown, context?: string): StandardSchemaV1;

Throws <context> must implement Standard Schema (~standard.validate). unless schema has a ~standard.validate function.

BaseRegistry

Abstract, mutable class for plugin systems that register at runtime. Prefer createRegistry otherwise.

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;
}

Methods

MethodReturnsDescription
register(item)voidRegisters an item. Logs warning on override.
has(key)booleanChecks if key exists
get(key)TValue | undefinedGets item by key
getAll()TValue[]Returns all items
getAllKeys()TKey[]Returns all keys
sizenumberCount of items
clear()voidRemoves all items

Protected Methods

MethodDescription
getItemKey(item)Extracts key from item (uses $type)
getItemName(item)Extracts name from item (uses metadata.name)

Types

BaseRegistration

import type { StandardSchemaV1 } from '@standard-schema/spec';

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

Zod Mini, Zod, Valibot, and Effect Schema values implement Standard Schema and remain valid schema values.

RegistrationMetadata

interface RegistrationMetadata {
	name: string;
	description?: string;
}

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 extends RegistrationMetadata {
	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 };

YAML subpath

@schema-engine/registry/yaml parses YAML documents and validates them with any validator that reports Standard Schema issues, then points each issue at a line and column. It needs the optional peer dependency yaml; the root entry never imports it.

parseYaml<T>(text: string, validate: YamlValidate<T>, options?: { filename?: string }): T; // throws YamlDocumentError
safeParseYaml<T>(text: string, validate: YamlValidate<T>, options?: { filename?: string }): { success: true; data: T } | { success: false; issues: YamlIssue[] };
stringifyYaml(value: unknown, options?: { schemaUrl?: string }): string;

type YamlIssue = { message: string; path: PropertyKey[]; line: number; column: number; filename?: string };

type YamlValidate<T> = (
	value: unknown,
) =>
	| { success: true; data: T }
	| {
			success: false;
			issues: ReadonlyArray<{ message: string; path?: ReadonlyArray<PropertyKey | { key: PropertyKey }> }>;
	  };

class YamlDocumentError extends Error {
	issues: YamlIssue[];
}

YamlValidate is any synchronous function that returns Standard Schema issues: engine.safeValidateForm from @schema-engine/forms fits as it is, and a Standard Schema's ~standard.validate fits once wrapped. YamlDocumentError is what parseYaml throws; its message lists one file:line:column path: message line per issue.

See YAML Forms for recipes, and the package README for the caveats.