/** * Base class for registries with indexed lookups. * * Provides: * - O(1) lookups by qualified ID, name, owner * - Child registry adoption with live subscriptions * - Lineage management for tracking ownership * - Change event emission for subscribers * * Extended by ToolRegistry, ResourceRegistry, PromptRegistry, AgentRegistry. */ import type { Token } from '../interfaces/base.interface.js'; import { RegistryAbstract, type RegistryKind } from './registry.base.js'; import type { IndexedEntry, EntryLineage, EntryOwnerRef, ChangeEvent, ChangeKind, SubscribeOptions, RegistryEmitter } from './indexed.types.js'; /** * Abstract base class for registries with indexed lookups. * * @typeParam TInstance - Type of registry entry instances * @typeParam TRecord - Type of registry records * @typeParam TIndexed - Type of indexed entries (extends IndexedEntry) * @typeParam TMetadata - Type of initialization metadata * @typeParam TProviders - Type of parent provider registry */ export declare abstract class IndexedRegistry, TMetadata, TProviders = unknown> extends RegistryAbstract { /** Entries created by this registry */ protected localRows: TIndexed[]; /** Entries adopted from child registries */ protected adopted: Map, TIndexed[]>; /** Set of child registries */ protected children: Set>; /** Unsubscribe functions for child subscriptions */ protected childSubscriptions: Map, () => void>; /** O(1) lookup by qualified ID */ protected byQualifiedId: Map; /** O(1) lookup by base name (array for conflicts) */ protected byName: Map; /** O(1) lookup by owner key */ protected byOwner: Map; /** O(1) lookup by owner:name composite */ protected byOwnerAndName: Map; /** Version counter for change tracking */ protected version: number; /** Event emitter for change notifications */ protected emitter: RegistryEmitter>; /** * Create an event emitter for this registry. * Override to use custom emitter implementation. */ protected createEmitter(): RegistryEmitter>; protected constructor(name: RegistryKind, providers: TProviders, metadata: TMetadata, auto?: boolean); /** * Build additional indexes from rows. * Called during reindex to populate custom indexes. * * @param rows - All indexed entries (local + adopted) */ protected abstract buildIndexes(rows: TIndexed[]): void; /** * Create an indexed entry from a record. * Called during initialization to wrap records. * * @param token - Entry token * @param record - Entry record * @param instance - Instantiated entry * @returns Indexed entry wrapper */ protected abstract makeRow(token: Token, record: TRecord, instance: TInstance): TIndexed; /** * Adopt entries from a child registry. * * @param child - Child registry to adopt from * @param childOwner - Owner reference for lineage */ adoptFromChild(child: IndexedRegistry, childOwner: EntryOwnerRef): void; /** * Remove a child registry. */ removeChild(child: IndexedRegistry): void; /** * Relineage an entry with a new prefix. * Creates a new indexed entry with updated lineage. */ protected relineage(row: TIndexed, prepend: EntryLineage): TIndexed; /** * Remove adjacent duplicate segments from lineage. */ protected dedupLineage(lineage: EntryLineage): EntryLineage; /** * Generate owner key from lineage. */ protected ownerKeyOf(lineage: EntryLineage): string; /** * Generate qualified name from base name and lineage. */ protected qualifiedNameOf(baseName: string, lineage: EntryLineage): string; /** * Rebuild all indexes from local and adopted entries. */ protected reindex(): void; /** * Subscribe to change events. */ subscribe(opts: SubscribeOptions, callback: (event: ChangeEvent) => void): () => void; /** * Emit a change event. */ protected bump(kind: ChangeKind): void; /** * Find by base name (returns first match). */ findByName(name: string): TInstance | undefined; /** * Find all by base name. */ findAllByName(name: string): TInstance[]; /** * Find by qualified ID. */ findByQualifiedId(qualifiedId: string): TInstance | undefined; /** * List all indexed entries by owner. */ listByOwner(ownerKey: string): TIndexed[]; /** * List all indexed entries. */ listAllIndexed(): TIndexed[]; /** * List all instances. */ listAllInstances(): TInstance[]; /** * Check if registry has any entries. */ hasAny(): boolean; /** * Dispose of this registry and clean up subscriptions. */ dispose(): void; }