tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
88 lines • 3.98 kB
text/typescript
export default TinyClassManager;
export type NewTinyClass = new (...args: any[]) => any;
export type PluginDefinition<TBase extends NewTinyClass, TExtended extends NewTinyClass, AppliedPluginClasses extends NewTinyClass[]> = {
/**
* - The unique identifier for the plugin.
*/
name: string;
/**
* - Array of plugin names required before applying this one.
*/
dependencies?: string[] | undefined;
/**
* - Function that receives the base class and returns the extended class.
*/
apply: (arg0: TBase, arg1: AppliedPluginClasses) => TExtended;
};
/** @typedef {new (...args: any[]) => any} NewTinyClass */
/**
* @template {NewTinyClass} TBase
* @template {NewTinyClass} TExtended
* @template {NewTinyClass[]} AppliedPluginClasses
* @typedef {Object} PluginDefinition
* @property {string} name - The unique identifier for the plugin.
* @property {string[]} [dependencies] - Array of plugin names required before applying this one.
* @property {function(TBase, AppliedPluginClasses): TExtended} apply - Function that receives the base class and returns the extended class.
*/
/**
* Manages the composition of a base class with multiple optional plugins (Mixins).
* @template {NewTinyClass} T
* @template {T|NewTinyClass} oldT
*/
declare class TinyClassManager<T extends NewTinyClass, oldT extends T | NewTinyClass> {
/**
* Initializes the manager with a core class.
* @param {T} coreClass - The foundational class to be extended.
* @param {oldT[]} [oldClasses=[]]
*/
constructor(coreClass: T, oldClasses?: oldT[]);
/**
* Gets the list of plugins currently applied to this instance.
* @returns {string[]} Array of applied plugin names.
*/
get appliedPlugins(): string[];
/**
* Gets the list of plugin classes currently applied to this instance.
* @returns {AppliedPluginClasses} Array of applied plugin classes.
*/
get appliedPluginClasses(): [...oldT[], T];
/**
* Gets the total size of the current class chain hierarchy.
* @returns {number} The count of applied plugins plus the core base.
*/
get size(): number;
/**
* Holds the current state of the class chain.
*/
get currentClass(): T;
/**
* Protects the instance from being consumed or reused after transition.
*/
get used(): boolean;
/**
* Applies a plugin to the class chain using a definition object.
* @deprecated Use {@link insert} instead.
* @template {NewTinyClass} R
* @param {PluginDefinition<T, R, AppliedPluginClasses>} plugin - The plugin module to be integrated.
* @returns {TinyClassManager<R, T | oldT>} A new manager instance holding the extended class chain.
* @throws {Error} Throws if instance is already consumed, plugin is duplicate, or dependencies are missing.
*/
use<R extends NewTinyClass>(plugin: PluginDefinition<T, R, [...oldT[], T]>): TinyClassManager<R, T | oldT>;
/**
* Inserts a plugin directly by passing its apply function.
* It reads `_tinyDepName` and `_tinyDeps` statically from the returned class.
* @template {NewTinyClass} R
* @param {function(T, AppliedPluginClasses): R} applyFn - Function that receives the base class and returns the extended class.
* @returns {TinyClassManager<R, T | oldT>} A new manager instance holding the extended class chain.
* @throws {Error} Throws if static properties are missing, instance is consumed, or validation fails.
*/
insert<R extends NewTinyClass>(applyFn: (arg0: T, arg1: [...oldT[], T]) => R): TinyClassManager<R, T | oldT>;
/**
* Finalizes the composition and returns the fully built class.
* @returns {T} The final class representing the last extended version in the chain.
* @throws {Error} Throws if the manager instance has already been used or finalized.
*/
build(): T;
#private;
}
//# sourceMappingURL=TinyClassManager.d.mts.map