UNPKG

@elsikora/cladi

Version:

ClaDI is a library for creating and managing classes in TypeScript.

74 lines 2.66 kB
import type { IRegistry } from '../../../domain/interface/index'; import type { IBaseRegistryOptions } from '../../interface/index'; /** * Generic registry implementation that stores items by name. * @template T The type of items stored in the registry. * @see {@link https://elsikora.com/docs/cladi/core-concepts/registry} */ export declare class BaseRegistry<T extends { getName(): string; }> implements IRegistry<T> { private readonly CACHE; private readonly ITEMS; private readonly LOGGER; /** * Creates a new registry instance. * @param {IBaseRegistryOptions} options Registry creation options including logger. */ constructor(options: IBaseRegistryOptions); /** * Clear the registry. */ clear(): void; /** * Get a single item from the registry by name. * @param {string} name The name of the item to get. * @returns {T | undefined} The item or undefined if it doesn't exist. */ get(name: string): T | undefined; /** * Get all items from the registry. * @returns {Array<T>} An array of all items. */ getAll(): Array<T>; /** * Get multiple items from the registry by their names. * @param {Array<string>} names The names of the items to get. * @returns {Array<T>} An array of items. */ getMany(names: Array<string>): Array<T>; /** * Check if an item exists in the registry by name. * @param {string} name The name of the item to check. * @returns {boolean} True if the item exists, false otherwise. */ has(name: string): boolean; /** * Register a single item in the registry. * @param {T} item The item to register. * @throws ValidationError if the item is invalid. */ register(item: T): void; /** * Register multiple items in the registry. * @param {Array<T>} items The items to register. * @throws ValidationError if any item is invalid. */ registerMany(items: Array<T>): void; /** * Unregister a single item from the registry by name. * @param {string} name The name of the item to unregister. */ unregister(name: string): void; /** * Unregister multiple items from the registry by their names. * @param {Array<string>} names The names of the items to unregister. */ unregisterMany(names: Array<string>): void; /** * Clear the cache for a specific query or all caches if no query is provided. * @param {string} [cacheKey] Optional cache key to clear. If not provided, all caches are cleared. */ private clearCache; } //# sourceMappingURL=registry.class.d.ts.map