UNPKG

@aedart/support

Version:

The Ion support package

1,181 lines (1,152 loc) 38 kB
/** * @aedart/support * * BSD-3-Clause, Copyright (c) 2023-present Alin Eugen Deac <aedart@gmail.com>. */ import { Concern, PROVIDES, BEFORE, UsesConcerns, AFTER, Container, ConcernConstructor, Owner, Injector, Factory, DescriptorsRepository, AliasDescriptorFactory, Configuration, ShorthandConfiguration, Alias, Aliases, ConcernException, InjectionException, AliasConflictException, AlreadyRegisteredException, BootException, NotRegisteredException, UnsafeAliasException } from '@aedart/contracts/support/concerns'; import { ClassBlueprint } from '@aedart/contracts/support/reflections'; import { ConstructorLike } from '@aedart/contracts'; /** * Abstract Concern * * @see {Concern} * @see [ConcernConstructor]{@link import('@aedart/contracts/support/concerns').ConcernConstructor} * @see [RegistrationAware]{@link import('@aedart/contracts/support/concerns').RegistrationAware} * * @implements {Concern} * * @abstract */ declare abstract class AbstractConcern implements Concern { /** * The owner class instance this concern is injected into, * or `this` concern instance. * * @type {object} * * @readonly * @protected */ protected readonly _concernOwner: object; /** * Creates a new concern instance * * @param {object} [owner] The owner class instance this concern is injected into. * Defaults to `this` concern instance if none given. * * @throws {Error} When concern is unable to preform initialisation, e.g. caused * by the owner or other circumstances. */ constructor(owner?: object); /** * The owner class instance this concern is injected into, * or `this` concern instance if no owner was set. * * @readonly * * @type {object} */ get concernOwner(): object; /** * Returns list of property keys that this concern class offers. * * **Note**: _Only properties and methods returned by this method can be aliased * into a target class._ * * @static * * @return {PropertyKey[]} */ static [PROVIDES](): PropertyKey[]; /** * Perform pre-registration logic. * * **Note**: _This hook method is intended to be invoked by an * [Injector]{@link import('@aedart/contracts/support/concerns').Injector}, before * the concern container and aliases are defined in the target class._ * * @static * * @param {UsesConcerns} target Target class constructor * * @return {void} * * @throws {Error} */ static [BEFORE](target: UsesConcerns): void; /** * Perform post-registration logic. * * **Note**: _This hook method is intended to be invoked by an * [Injector]{@link import('@aedart/contracts/support/concerns').Injector}, after * this concern class has been registered in a target class and aliases have been * defined in target's prototype._ * * @static * * @param {UsesConcerns} target Target class constructor, after concerns and aliases defined * * @return {void} * * @throws {Error} */ static [AFTER](target: UsesConcerns): void; } /** * Concern Class Blueprint * * Defines the minimum members that a target class should contain, before it is * considered to "look like" a [Concern Class]{@link import('@aedart/contracts/support/concerns').ConcernConstructor} * * @see ClassBlueprint */ declare const ConcernClassBlueprint: ClassBlueprint; /** * Concerns Container * * @see Container */ declare class ConcernsContainer implements Container { /** * Map of concern class constructors and actual concern instances * * @protected * @readonly * * @type {Map<ConcernConstructor, Concern|undefined>} */ protected readonly map: Map<ConcernConstructor, Concern | undefined>; /** * The concerns owner of this container * * @type {Owner} * * @protected * @readonly */ protected readonly _owner: Owner; /** * Create a new Concerns Container instance * * @param {Owner} owner * @param {ConcernConstructor[]} concerns */ constructor(owner: Owner, concerns: ConcernConstructor[]); /** * The amount of concerns in this container * * @readonly * * @type {number} */ get size(): number; /** * Get the concerns container owner * * @readonly * * @type {Owner} */ get owner(): Owner; /** * Determine if concern class is registered in this container * * @param {ConcernConstructor} concern * * @return {boolean} */ has(concern: ConcernConstructor): boolean; /** * Retrieve concern instance for given concern class * * **Note**: _If concern class is registered in this container, but not yet * booted, then this method will boot it via the {@link boot} method, and return * the resulting instance._ * * @template T extends {@link Concern} * * @param {ConcernConstructor<T>} concern * * @return {T} The booted instance of the concern class. If concern class was * previously booted, then that instance is returned. * * @throws {ConcernError} */ get<T extends Concern>(concern: ConcernConstructor<T>): T; /** * Determine if concern class has been booted * * @param {ConcernConstructor} concern * * @return {boolean} */ hasBooted(concern: ConcernConstructor): boolean; /** * Boot concern class * * @template T extends {@link Concern} * * @param {ConcernConstructor<T>} concern * * @return {T} New concern instance * * @throws {NotRegisteredError} If concern class is not registered in this container * @throws {BootError} If concern is unable to be booted, e.g. if already booted */ boot<T extends Concern>(concern: ConcernConstructor<T>): T; /** * Boots all registered concern classes * * @throws {ConcernError} */ bootAll(): void; /** * Determine if this container is empty * * @return {boolean} */ isEmpty(): boolean; /** * Opposite of {@link isEmpty} * * @return {boolean} */ isNotEmpty(): boolean; /** * Returns all concern classes * * @return {IterableIterator<ConcernConstructor>} */ all(): IterableIterator<ConcernConstructor>; /** * Invoke a method with given arguments in concern instance * * @param {ConcernConstructor} concern * @param {PropertyKey} method * @param {...any} [args] * * @return {any} * * @throws {ConcernError} * @throws {Error} */ call(concern: ConcernConstructor, method: PropertyKey, ...args: any[]): any; /** * Set the value of given property in concern instance * * @param {ConcernConstructor} concern * @param {PropertyKey} property * @param {any} value * * @throws {ConcernError} * @throws {Error} */ setProperty(concern: ConcernConstructor, property: PropertyKey, value: any): void; /** * Get value of given property in concern instance * * @param {ConcernConstructor} concern * @param {PropertyKey} property * * @return {any} * * @throws {ConcernError} * @throws {Error} */ getProperty(concern: ConcernConstructor, property: PropertyKey): any; } /** * Concerns Injector * * @see Injector */ declare class ConcernsInjector<T = object> implements Injector<T> { /** * The target class * * @template T = object * @type {T} * * @protected */ protected readonly _target: T; /** * Concern Configuration Factory * * @type {Factory} * * @protected */ protected configFactory: Factory; /** * Descriptors Repository * * @type {DescriptorsRepository} * * @protected */ protected repository: DescriptorsRepository; /** * Alias Descriptor Factory * * @type {AliasDescriptorFactory} * * @protected */ protected descriptorFactory: AliasDescriptorFactory; /** * Create a new Concerns Injector instance * * @template T = object * * @param {T} target The target class that concerns must be injected into * @param {Factory} [configFactory] * @param {AliasDescriptorFactory} [descriptorFactory] * @param {DescriptorsRepository} [repository] */ constructor(target: T, configFactory?: Factory, descriptorFactory?: AliasDescriptorFactory, repository?: DescriptorsRepository); /** * The target class * * @template T = object * * @returns {T} */ get target(): T; /** * Injects concern classes into the target class and return the modified target. * * **Note**: _Method performs injection in the following way:_ * * _**A**: Defines the concern classes in target class, via {@link defineConcerns}._ * * _**B**: Defines a concerns container in target class' prototype, via {@link defineContainer}._ * * _**C**: Defines "aliases" (proxy properties and methods) in target class' prototype, via {@link defineAliases}._ * * @template T = object The target class that concern classes must be injected into * * @param {...ConcernConstructor | Configuration | ShorthandConfiguration} concerns List of concern classes / injection configurations * * @returns {UsesConcerns<T>} The modified target class * * @throws {InjectionException} */ inject(...concerns: (ConcernConstructor | Configuration | ShorthandConfiguration)[]): UsesConcerns<T>; /** * Defines the concern classes that must be used by the target class. * * **Note**: _Method changes the target class, such that it implements and respects the * {@link UsesConcerns} interface._ * * @template T = object * * @param {T} target The target class that must define the concern classes to be used * @param {Constructor<Concern>[]} concerns List of concern classes * * @returns {UsesConcerns<T>} The modified target class * * @throws {AlreadyRegisteredError} * @throws {InjectionError} */ defineConcerns<T = object>(target: T, concerns: ConcernConstructor[]): UsesConcerns<T>; /** * Defines a concerns {@link Container} in target class' prototype. * * **Note**: _Method changes the target class, such that it implements and respects the * [Owner]{@link import('@aedart/contracts/support/concerns').Owner} interface!_ * * @template T = object * * @param {UsesConcerns<T>} target The target in which a concerns container must be defined * * @returns {UsesConcerns<T>} The modified target class * * @throws {InjectionError} If unable to define concerns container in target class */ defineContainer<T = object>(target: UsesConcerns<T>): UsesConcerns<T>; /** * Defines "aliases" (proxy properties and methods) in target class' prototype, such that they * point to the properties and methods available in the concern classes. * * **Note**: _Method defines each alias using the {@link defineAlias} method!_ * * @template T = object * * @param {UsesConcerns<T>} target The target in which "aliases" must be defined in * @param {Configuration[]} configurations List of concern injection configurations * * @returns {UsesConcerns<T>} The modified target class * * @throws {AliasConflictError} If case of alias naming conflicts. * @throws {InjectionError} If unable to define aliases in target class. */ defineAliases<T = object>(target: UsesConcerns<T>, configurations: Configuration[]): UsesConcerns<T>; /** * Defines an "alias" (proxy property or method) in target class' prototype, which points to a property or method * in the given concern. * * **Note**: _Method will do nothing, if a property or method already exists in the target class' prototype * chain, with the same name as given "alias"._ * * @template T = object * * @param {UsesConcerns<T>} target The target in which "alias" must be defined in * @param {PropertyKey} alias Name of the "alias" in the target class (name of the proxy property or method) * @param {PropertyKey} key Name of the property or method that the "alias" points to, in the concern class (`source`) * @param {Constructor} source The source concern class that contains the property or methods that is pointed to (`key`) * * @returns {boolean} `true` if "alias" was in target class. `false` if a property or method already exists in the * target, with the same name as the "alias". * * @throws {UnsafeAliasError} If an alias points to an "unsafe" property or method in the source concern class. * @throws {InjectionException} If unable to define "alias" in target class. */ defineAlias<T = object>(target: UsesConcerns<T>, alias: PropertyKey, key: PropertyKey, source: ConcernConstructor): boolean; /** * Normalises given concerns into a list of concern configurations * * @param {(ConcernConstructor | Configuration | ShorthandConfiguration)[]} concerns * * @returns {Configuration[]} * * @throws {InjectionError} */ normalise(concerns: (ConcernConstructor | Configuration | ShorthandConfiguration)[]): Configuration[]; /***************************************************************** * Internals ****************************************************************/ /** * Resolves the concern classes to be registered (registry), for the given target * * **Note**: _Method ensures that if target already has concern classes defined, then those * are merged into the resulting list._ * * @param {object} target * @param {ConcernConstructor[]} concerns * * @returns {ConcernConstructor[]} Registry with concern classes that are ready to be registered in given target * * @throws {AlreadyRegisteredError} If a concern has already been registered in the target * * @protected */ protected resolveConcernsRegistry(target: object, concerns: ConcernConstructor[]): ConcernConstructor[]; /** * Normalises the given entry into a concern configuration * * @param {ConcernConstructor | Configuration | ShorthandConfiguration} entry * * @returns {Configuration} * * @throws {InjectionError} * * @protected */ protected normaliseEntry(entry: ConcernConstructor | Configuration | ShorthandConfiguration): Configuration; /** * Defines a property in given target * * @template T = object * * @param {T} target * @param {PropertyKey} property * @param {PropertyDescriptor} descriptor * @param {string} [failMessage] * * @returns {T} * * @throws {InjectionError} * * @protected */ protected definePropertyInTarget<T = object>(target: T, property: PropertyKey, descriptor: PropertyDescriptor, failMessage?: string): T; /** * Find the source class where given concern is registered * * @param {ConcernConstructor} concern * @param {object} target * @param {boolean} [includeTarget=false] * * @returns {object | null} The source class, e.g. parent of target class, or `null` if concern is not registered * in target or target's parents. * * @protected */ protected findSourceOf(concern: ConcernConstructor, target: object, includeTarget?: boolean): object | null; /** * Returns all applied aliases for given target and its parent classes * * @param {UsesConcerns} target * @param {boolean} [includeTarget=false] * * @return {Map<Alias, UsesConcerns>} * * @protected */ protected getAllAppliedAliases(target: UsesConcerns, includeTarget?: boolean): Map<Alias, UsesConcerns>; /** * Processes given configuration's aliases by defining them * * @param {UsesConcerns} target * @param {Configuration} configuration * @param {Alias[]} applied * @param {Map<Alias, UsesConcerns>} appliedByParents * * @return {Alias[]} New applied aliases (does not include aliases from `applied` argument) * * @protected * * @throws {AliasConflictError} */ protected processAliases(target: UsesConcerns, configuration: Configuration, applied: Alias[], appliedByParents: Map<Alias, UsesConcerns>): Alias[]; /** * Assert that given alias does not conflict with an already applied alias * * @param {UsesConcerns} target * @param {ConcernConstructor} concern * @param {Alias} alias * @param {PropertyKey} key * @param {Alias} applied Aliases that are applied directly in the target class * @param {Map<Alias, UsesConcerns>} appliedByParents Aliases that are applied in target's parents * * @protected * * @throws {AliasConflictError} */ protected assertAliasDoesNotConflict(target: UsesConcerns, concern: ConcernConstructor, alias: Alias, key: PropertyKey, applied: Alias[], appliedByParents: Map<Alias, UsesConcerns>): void; /** * Determine if key is "unsafe" * * @param {PropertyKey} key * * @returns {boolean} * * @protected */ protected isUnsafe(key: PropertyKey): boolean; /** * Invokes the {@link BEFORE} hook method in concern classes * * @param {UsesConcerns} target * @param {ConcernConstructor[]} concerns All concern classes in target's prototype chain * * @protected * * @throws {InjectionError} */ protected callBeforeRegistration(target: UsesConcerns, concerns: ConcernConstructor[]): void; /** * Invokes the {@link AFTER} hook method in concern classes * * @param {UsesConcerns} target * @param {ConcernConstructor[]} concerns All concern classes in target's prototype chain * * @protected * * @throws {InjectionError} */ protected callAfterRegistration(target: UsesConcerns, concerns: ConcernConstructor[]): void; /** * Invokes the registration hook in given concern classes * * @param {UsesConcerns} target * @param {ConcernConstructor} concerns * @param {symbol} hook * @param {string} name * * @protected * * @throws {InjectionError} */ protected callRegistrationHook(target: UsesConcerns, concerns: ConcernConstructor[], hook: symbol, name: string): void; } /** * Concern Configuration Factory * * @see Factory */ declare class ConfigurationFactory implements Factory { /** * Returns a new normalised concern configuration for given concern "entry" * * **Note**: _"normalised" in this context means:_ * * _**A**: If a concern class is given, then a new concern configuration made._ * * _**B**: If configuration is given, then a new concern configuration and given * configuration is merged into the new configuration._ * * _**C**: Configuration's `aliases` are automatically populated. When a concern * configuration is provided, its evt. aliases merged with the default ones, * unless `allowAliases` is set to `false`, in which case all aliases are removed._ * * @param {object} target * @param {ConcernConstructor | Configuration | ShorthandConfiguration} entry * * @returns {Configuration} * * @throws {InjectionException} If entry is unsupported or invalid */ make(target: object, entry: ConcernConstructor | Configuration | ShorthandConfiguration): Configuration; /** * Casts the shorthand configuration to a configuration object * * @param {ShorthandConfiguration} config * * @return {Configuration} * * @protected */ protected makeFromShorthand(config: ShorthandConfiguration): Configuration; /** * Returns a new concern configuration for the given concern class * * @param {ConcernConstructor} concern * * @returns {Configuration} * * @protected */ protected makeConfiguration(concern: ConcernConstructor): Configuration; /** * Returns the default aliases that are provided by the given concern class * * @param {ConcernConstructor} concern * * @returns {Aliases} * * @protected */ protected makeDefaultAliases(concern: ConcernConstructor): Aliases; /** * Removes evt. "unsafe" keys from configuration's aliases * * @param {Configuration} configuration * * @returns {Configuration} * * @protected */ protected removeUnsafeKeys(configuration: Configuration): Configuration; /** * Determine if key is "unsafe" * * @param {PropertyKey} key * * @returns {boolean} * * @protected */ protected isUnsafe(key: PropertyKey): boolean; } /** * Repository * * @see DescriptorsRepository */ declare class Repository implements DescriptorsRepository { /** * In-memory cache property descriptors for target class and concern classes * * @type {WeakMap<ConstructorLike | UsesConcerns | ConcernConstructor, Record<PropertyKey, PropertyDescriptor>>} * * @protected */ protected _store: WeakMap<ConstructorLike | UsesConcerns | ConcernConstructor, Record<PropertyKey, PropertyDescriptor>>; /** * Create new Descriptors instance */ constructor(); /** * Returns property descriptors for given target class (recursively) * * @param {ConstructorLike | UsesConcerns | ConcernConstructor} target The target class, or concern class * @param {boolean} [force=false] If `true` then method will not return evt. cached descriptors. * @param {boolean} [cache=false] Caches the descriptors if `true`. * * @returns {Record<PropertyKey, PropertyDescriptor>} */ get(target: ConstructorLike | UsesConcerns | ConcernConstructor, force?: boolean, cache?: boolean): Record<PropertyKey, PropertyDescriptor>; /** * Caches property descriptors for target during the execution of callback. * * @param {ConstructorLike | UsesConcerns | ConcernConstructor} target The target class, or concern class * @param {() => any} callback Callback to invoke * @param {boolean} [forgetAfter=true] It `true`, cached descriptors are deleted after callback is invoked */ rememberDuring(target: ConstructorLike | UsesConcerns | ConcernConstructor, callback: () => any, /* eslint-disable-line @typescript-eslint/no-explicit-any */ forgetAfter?: boolean): any; /** * Retrieves the property descriptors for given target and caches them * * @param {ConstructorLike | UsesConcerns | ConcernConstructor} target The target class, or concern class * @param {boolean} [force=false] If `true` then evt. previous cached result is not used. * * @returns {Record<PropertyKey, PropertyDescriptor>} */ remember(target: ConstructorLike | UsesConcerns | ConcernConstructor, force?: boolean): Record<PropertyKey, PropertyDescriptor>; /** * Deletes cached descriptors for target * * @param {ConstructorLike | UsesConcerns | ConcernConstructor} target * * @return {boolean} */ forget(target: ConstructorLike | UsesConcerns | ConcernConstructor): boolean; /** * Clears all cached descriptors * * @return {this} */ clear(): this; } /** * Alias Descriptor Factory * * @see AliasDescriptorFactory */ declare class DescriptorFactory implements AliasDescriptorFactory { /** * Returns a property descriptor to be used for an "alias" property or method in a target class * * @param {PropertyKey} key The property key in `source` concern * @param {ConcernConstructor} source The concern that holds the property key * @param {PropertyDescriptor} keyDescriptor Descriptor of `key` in `source` * * @returns {PropertyDescriptor} Descriptor to be used for defining alias in a target class */ make(key: PropertyKey, source: ConcernConstructor, keyDescriptor: PropertyDescriptor): PropertyDescriptor; /** * Returns a new proxy "method" for given method in this concern * * @param {PropertyKey} method * @param {ConcernConstructor} concern * * @returns {(...args: any[]) => any} * * @protected */ protected makeMethodProxy(method: PropertyKey, concern: ConcernConstructor): (...args: any[]) => any; /** * Returns a new proxy "get" for given property in this concern * * @param {PropertyKey} property * @param {ConcernConstructor} concern * * @returns {() => any} * * @protected */ protected makeGetPropertyProxy(property: PropertyKey, concern: ConcernConstructor): () => any; /** * Returns a new proxy "set" for given property in this concern * * @param {PropertyKey} property * @param {ConcernConstructor} concern * * @returns {(value: any) => void} * * @protected */ protected makeSetPropertyProxy(property: PropertyKey, concern: ConcernConstructor): (value: any) => void; } /** * Concern Error * * @see ConcernException */ declare class ConcernError extends Error implements ConcernException { /** * The Concern class that caused this error or exception * * @type {ConcernConstructor | null} * * @protected * @readonly */ protected readonly _concern: ConcernConstructor | null; /** * Create a new Concern Error instance * * @param {ConcernConstructor | null} concern * @param {string} message * @param {ErrorOptions} [options] */ constructor(concern: ConcernConstructor | null, message: string, options?: ErrorOptions); /** * The Concern class that caused this error or exception * * @readonly * * @type {ConcernConstructor | null} */ get concern(): ConcernConstructor | null; } /** * Injection Error * * @see InjectionException */ declare class InjectionError extends ConcernError implements InjectionException { /** * The target class * * @type {ConstructorLike|UsesConcerns} * * @protected * @readonly */ protected readonly _target: ConstructorLike | UsesConcerns; /** * Create a new Injection Error instance * * @param {ConstructorLike | UsesConcerns} target * @param {ConcernConstructor | null} concern * @param {string} message * @param {ErrorOptions} [options] */ constructor(target: ConstructorLike | UsesConcerns, concern: ConcernConstructor | null, message: string, options?: ErrorOptions); /** * The target class * * @readonly * * @returns {ConstructorLike | UsesConcerns} */ get target(): ConstructorLike | UsesConcerns; } /** * Alias Conflict Error * * @see AliasConflictException */ declare class AliasConflictError extends InjectionError implements AliasConflictException { /** * The requested alias that conflicts with another alias * of the same name. * * @type {Alias} * * @readonly * @protected */ protected readonly _alias: Alias; /** * the property key that the conflicting alias points to * * @type {PropertyKey} * * @readonly * @protected */ readonly _key: PropertyKey; /** * The source class (e.g. parent class) that defines that originally defined the alias * * @type {ConstructorLike | UsesConcerns} * * @readonly * @protected */ protected readonly _source: ConstructorLike | UsesConcerns; /** * Create a new Alias Conflict Error instance * * @param {ConstructorLike | UsesConcerns} target * @param {ConcernConstructor} concern * @param {Alias} alias * @param {PropertyKey} key * @param {ConstructorLike | UsesConcerns} source * @param {ErrorOptions} [options] */ constructor(target: ConstructorLike | UsesConcerns, concern: ConcernConstructor, alias: Alias, key: PropertyKey, source: ConstructorLike | UsesConcerns, options?: ErrorOptions); /** * The requested alias that conflicts with another alias * of the same name. * * @readonly * * @type {Alias} */ get alias(): Alias; /** * the property key that the conflicting alias points to * * @readonly * * @type {PropertyKey} */ get key(): PropertyKey; /** * The source class (e.g. parent class) that defines that originally defined the alias * * @readonly * * @type {ConstructorLike | UsesConcerns} */ get source(): ConstructorLike | UsesConcerns; } /** * Already Registered Error * * @see AlreadyRegisteredException */ declare class AlreadyRegisteredError extends InjectionError implements AlreadyRegisteredException { /** * The source, e.g. a parent class, in which a concern class * was already registered. * * @type {ConstructorLike|UsesConcerns} * * @readonly * @protected */ protected readonly _source: ConstructorLike | UsesConcerns; /** * Create a new "already registered" error instance * * @param {ConstructorLike | UsesConcerns} target * @param {ConcernConstructor} concern * @param {ConstructorLike | UsesConcerns} source * @param {string} [message] * @param {ErrorOptions} [options] */ constructor(target: ConstructorLike | UsesConcerns, concern: ConcernConstructor, source: ConstructorLike | UsesConcerns, message?: string, options?: ErrorOptions); /** * The source, e.g. a parent class, in which a concern class * was already registered. * * @readonly * * @returns {ConstructorLike | UsesConcerns} */ get source(): ConstructorLike | UsesConcerns; } /** * Concern Boot Error * * @see BootException */ declare class BootError extends ConcernError implements BootException { /** * Create a new Concern Boot Error instance * * @param {ConcernConstructor} concern * @param {string} message * @param {ErrorOptions} [options] */ constructor(concern: ConcernConstructor, message: string, options?: ErrorOptions); } /** * Concern Not Registered Error * * @see NotRegisteredException */ declare class NotRegisteredError extends ConcernError implements NotRegisteredException { /** * Create a new Concern Not Registered Error instance * * @param {ConcernConstructor} concern * @param {ErrorOptions} [options] */ constructor(concern: ConcernConstructor, options?: ErrorOptions); } /** * Unsafe Alias Error */ declare class UnsafeAliasError extends InjectionError implements UnsafeAliasException { /** * The alias that points to an "unsafe" property or method * * @type {PropertyKey} * * @protected * @readonly */ protected readonly _alias: PropertyKey; /** * The "unsafe" property or method that an alias points to * * @type {PropertyKey} * * @protected * @readonly */ protected readonly _key: PropertyKey; /** * Create a new Unsafe Alias Error instance * * @param {ConstructorLike | UsesConcerns} target * @param {ConcernConstructor} concern * @param {PropertyKey} alias * @param {PropertyKey} key * @param {string} [message] * @param {ErrorOptions} [options] */ constructor(target: ConstructorLike | UsesConcerns, concern: ConcernConstructor, alias: PropertyKey, key: PropertyKey, message?: string, options?: ErrorOptions); /** * The alias that points to an "unsafe" property or method * * @readonly * * @type {PropertyKey} */ get alias(): PropertyKey; /** * The "unsafe" property or method that an alias points to * * @readonly * * @type {PropertyKey} */ get key(): PropertyKey; } /** * Assert that given instance is of the type [Concerns Owner]{@link import('@aedart/contracts/support/concerns').Owner} * * @see isConcernsOwner * * @param {object} instance * * @throws {TypeError} If `instance` is not of the type [Concerns Owner]{@link import('@aedart/contracts/support/concerns').Owner} */ declare function assertIsConcernsOwner(instance: object): void; /** * Boot all concerns for [owner]{@link Owner} instance * * @param {object|Owner} instance * * @return {void} * * @throws {TypeError} If `instance` is not of the type [Concerns Owner]{@link import('@aedart/contracts/support/concerns').Owner} * @throws {NotRegisteredError} If a concern class is not registered in this container * @throws {BootError} If a concern is unable to be booted, e.g. if already booted */ declare function bootAllConcerns(instance: object | Owner): void; /** * Boot given concerns for [owner]{@link Owner} instance * * @param {object|Owner} instance * @param {...ConcernConstructor[]} concerns * * @return {void} * * @throws {TypeError} If `instance` is not of the type [Concerns Owner]{@link import('@aedart/contracts/support/concerns').Owner} * @throws {NotRegisteredError} If a concern class is not registered in this container * @throws {BootError} If a concern is unable to be booted, e.g. if already booted */ declare function bootConcerns(instance: object | Owner, ...concerns: ConcernConstructor[]): void; /** * Returns [owner's]{@link Owner} [concerns container]{@link Container} * * @see assertIsConcernsOwner * @see getContainer * * @param {object|Owner} instance * * @return {Container} * * @throws {TypeError} If `instance` is not a [concerns owner]{@link Owner} */ declare function getConcernsContainer(instance: object | Owner): Container; /** * Returns [owner's]{@link Owner} [concerns container]{@link Container} * * **Caution**: _Method expects that given `owner` is type {@link Owner}!_ * * @see getConcernsContainer * * @param {Owner} owner * * @return {Container} */ declare function getContainer(owner: Owner): Container; /** * Determine if target a [Concern Configuration]{@link import('@aedart/contracts/support/concerns').Configuration} * * @param {object} target * @param {boolean} [force=false] If `false` then cached result is returned if available. * * @returns {boolean} */ declare function isConcernConfiguration(target: object, force?: boolean): boolean; /** * Determine if given target is a * [Concern Constructor]{@link import('@aedart/contracts/support/concerns').ConcernConstructor}. * * @param {any} target * @param {boolean} [force=false] If `false` then cached result is returned if available. * * @returns {boolean} */ declare function isConcernConstructor(target: any, /* eslint-disable-line @typescript-eslint/no-explicit-any */ force?: boolean): boolean; /** * Determine if object is of the type [Concerns Owner]{@link import('@aedart/contracts/support/concerns').Owner} * * @param {object} instance * * @return {boolean} */ declare function isConcernsOwner(instance: object): boolean; /** * Determine if target a [Shorthand Concern Configuration]{@link import('@aedart/contracts/support/concerns').ShorthandConfiguration} * * @param {object} target * @param {boolean} [force=false] If `false` then cached result is returned if available. * * @returns {boolean} */ declare function isShorthandConfiguration(target: object, force?: boolean): boolean; /** * List of property keys that are considered "unsafe" to alias (proxy to) */ declare const UNSAFE_PROPERTY_KEYS: PropertyKey[]; /** * Determine if given property key is considered "unsafe" * * @see UNSAFE_PROPERTY_KEYS * * @param {PropertyKey} key * * @returns {boolean} */ declare function isUnsafeKey(key: PropertyKey): boolean; /** * Injects the concern classes into the target class * * **Note**: _Method is intended to be used as a class decorator!_ * * **Example**: * ``` * @use( * MyConcernA, * MyConcernB, * { concern: MyConcernC, aliases: { 'foo': 'bar' } }, * ) * class MyClass {} * ``` * * @see Injector * @see ConcernConstructor * @see Configuration * @see UsesConcerns * * @template T = object * * @param {...Constructor | Configuration | ShorthandConfiguration} concerns * * @returns {(target: T) => UsesConcerns<T>} * * @throws {InjectionException} */ declare function use(...concerns: (ConcernConstructor | Configuration | ShorthandConfiguration)[]): any; /** * Determine if [concerns owner]{@link Owner} uses the given concerns * * @param {object|Owner} instance * @param {...ConcernConstructor[]} concerns * * @return {boolean} `true` if owner uses all given concerns, `false` otherwise. */ declare function usesConcerns(instance: object | Owner, ...concerns: ConcernConstructor[]): boolean; export { AbstractConcern, AliasConflictError, AlreadyRegisteredError, BootError, ConcernClassBlueprint, ConcernError, ConcernsContainer, ConcernsInjector, ConfigurationFactory, DescriptorFactory, InjectionError, NotRegisteredError, Repository, UNSAFE_PROPERTY_KEYS, UnsafeAliasError, assertIsConcernsOwner, bootAllConcerns, bootConcerns, getConcernsContainer, getContainer, isConcernConfiguration, isConcernConstructor, isConcernsOwner, isShorthandConfiguration, isUnsafeKey, use, usesConcerns };