import { BeforeAdvice, AfterAdvice, AroundAdvice } from './aspect'; /** * For a given factory, return the names of the initialization functions that will be * invoked upon construction. * * @param factory The factory that the array of function names should be returned for */ export declare function getInitFunctionNames(factory: ComposeFactory): string[] | undefined; /** * A custom type guard that determines if the value is a ComposeFactory * * @param value The target to check * @returns Return true if it is a ComposeFactory, otherwise false */ export declare function isComposeFactory(value: any): value is ComposeFactory; /** * Used to adapt any consructor functions or classes to a compose factory */ export interface GenericClass { new (...args: any[]): T; readonly prototype: T; } /** * Used to adapt functions within compose */ export interface GenericFunction { (...args: any[]): T; } /** * A basic string index map of options */ export interface Options { [options: string]: any; } export interface ComposeInitializationFunction { /** * A callback function use to initialize a new created instance * * @param instance The newly constructed instance * @param options Any options that were passed to the factory * @template T The type of the instance * @template O The type of the options being passed */ (instance: T, options?: O): void; /** * A string name of the function, used for debugging purposes */ readonly name?: string; } export interface ComposeFactory extends ComposeMixinable { /** * Extend the factory prototype with the supplied object literal, class, or factory * * @deprecated * @param extension The object literal, class or factory to extend * @template T The original type of the factory * @template U The type of the extension * @template O The type of the factory options * @template P The type of the extension factory options */ extend(extension: U | GenericClass): ComposeFactory; extend(className: string, extension: U | GenericClass): ComposeFactory; extend(extension: ComposeFactory): ComposeFactory; extend(className: string, extension: ComposeFactory): ComposeFactory; } export interface Compose { /** * Extend a compose factory prototype with the supplied object literal, class, or * factory. * * @deprecated * @param base The base compose factory to extend * @param extension The object literal, class or factory that is the extension * @template T The base type of the factory * @template U The type of the extension * @template O The type of the base factory options * @template P The type of the extension factory options */ extend(base: ComposeFactory, extension: U | GenericClass): ComposeFactory; extend(base: ComposeFactory, className: string, extension: U | GenericClass): ComposeFactory; extend(base: ComposeFactory, extension: ComposeFactory): ComposeFactory; extend(base: ComposeFactory, className: string, extension: ComposeFactory): ComposeFactory; } export interface ComposeFactory extends ComposeMixinable { /** * Override certain properties on the existing factory, returning a new factory. If the properties * are not present in the existing factory, override will throw. * * @param properties The properties to override */ override(properties: any): this; /** * Override certain properties on the existing factory, returning a new factory. If the properties * are not present in the existing factory, override with throw. * * @param className The class name for the factory * @param properties The properties to override */ override(className: string, properties: any): this; } export interface Compose { /** * Override properties on a compose factory, returning a new factory. If the properties are not * present on the base factory, override will throw. * * @param baseFactory The base compose factory to override * @param properties The properties to override */ override(baseFactory: ComposeFactory, properties: any): ComposeFactory; /** * Override properties on a compose factory, returning a new factory. If the properties are not * present on the base factory, override will throw. * * @param baseFactory The base compose factory to override * @param className The class name for the factory * @param properties The properties to override */ override(baseFactory: ComposeFactory, className: string, properties: any): ComposeFactory; } export interface OverlayFunction { /** * A function that takes a factories prototype, allowing it to change the prototype without * mutating the type structure. * * @param proto The object literal that should be overlayed on the factories prototype. * @template T The type of the factories prototype */ (proto: T): void; } export interface ComposeFactory extends ComposeMixinable { /** * Provide a function that mutates the factories prototype but does not change the factory's class * structure. * * @param overlayFunction The function which receives the factory's prototype * @template T The type of the factory's prototype */ overlay(overlayFunction: OverlayFunction): this; } export interface Compose { /** * A static method that takes a compose factory and applies an overlay function to the factory, * returning a new compose factory with a mutated prototype. * * @param base The base ComposeFactory * @param overlayFunction The function which receives the base factory's prototype * @template T The type of the factory's prototype * @template O The options for the factory's creation */ overlay(base: ComposeFactory, overlayFunction: OverlayFunction): ComposeFactory; } /** * A descriptor for applying advice to a set of methods */ export interface AspectAdvice { /** * Any methods where the supplied advice should be applied *before* the base method is invoked */ before?: { [method: string]: BeforeAdvice; }; /** * Any methods where the supplied advice should be applied *after* the base method is invoked */ after?: { [method: string]: AfterAdvice; }; /** * Any methods where the supplied advice should be applied *around* the base method */ around?: { [method: string]: AroundAdvice; }; } /** * Either a class, object literal, or a factory */ export declare type ComposeMixinItem = GenericClass | T | ComposeFactory; /** * An object which provides information on how to mixin into a compose factory */ export interface ComposeMixinDescriptor { /** * The class, object literal, or factory to be mixed in */ mixin?: ComposeMixinItem; /** * An initialize function to be executed upon construction */ initialize?: ComposeInitializationFunction; /** * Aspect Oriented Advice to be mixed into the factory */ aspectAdvice?: AspectAdvice; /** * An optional class name which is used when labelling different parts of a factory for * debugging purposes */ className?: string; } /** * Identifies a compose factory or other object that can be transformed into a * ComposeMixinDescriptor */ export interface ComposeMixinable { /** * A method that offers up a ComposeMixinDescriptor to allow complex mixin in of factories */ factoryDescriptor(): ComposeMixinDescriptor; } export interface ComposeFactory extends ComposeMixinable { /** * Mixin additional mixins, initialization logic, and aspect advice into the factory * * @param mixin An object literal that describes what to mixin */ mixin(mixin: ComposeMixinable): ComposeFactory; mixin(mixin: ComposeMixinDescriptor): ComposeFactory; } export interface Compose { /** * Mixin additional mixins, initialization logic, and aspect advice into a factory * * @param base The base factory that is the target of the mixin * @param mixin An object literal that describes what to mixin */ mixin(base: ComposeFactory, mixin: ComposeMixinable): ComposeFactory; mixin(base: ComposeFactory, mixin: ComposeMixinDescriptor): ComposeFactory; } export interface ComposeFactory extends ComposeMixinable { /** * Extract a method from another Class or Factory and add it to the returned factory * * @param base The base Class or Factory * @param method The name of the method to extract */ from(base: GenericClass | ComposeFactory, method: string): this; /** * Apply advice *before* the named method (join-point) * * @param method The method to apply the advice to * @param advice The advice to be applied */ before(method: string, advice: BeforeAdvice): this; /** * Apply advice *after* the named method (join-point) * * @param method The method to apply the advice to * @param advice The advice to be applied */ after

(method: string, advice: AfterAdvice

): this; /** * Apply advice *around* the named method (join-point) * * @param method The method to apply the advice to * @param advice The advice to be applied */ around

(method: string, advice: AroundAdvice

): this; /** * Provide an object literal which can contain a map of advice to apply * * @param advice An object literal which contains the maps of advice to apply */ aspect(advice: AspectAdvice): this; } export interface Compose { /** * Extract a method from another Class or Factory and return it * * @param base The Class or Factory to extract from * @param method The method name to be extracted */ from(base: GenericClass | ComposeFactory, method: string | symbol): T; /** * Apply advice *before* the named method (join-point) * * @param base The Class or Factory to extract the method from * @param method The method name to apply the advice to * @param advice The advice to apply */ before(base: GenericClass | ComposeFactory, method: string | symbol, advice: BeforeAdvice): GenericFunction; before(method: GenericFunction, advice: BeforeAdvice): GenericFunction; /** * Apply advice *after* the named method (join-point) * * @param base The Class or Factory to extract the method from * @param method The method name to apply the advice to * @param advice The advice to apply */ after(base: GenericClass | ComposeFactory, method: string | symbol, advice: AfterAdvice): GenericFunction; after(method: GenericFunction, advice: AfterAdvice): GenericFunction; /** * Apply advice *around* the named method (join-point) * * @param base The Class or Factory to extract the method from * @param method The method name to apply the advice to * @param advice The advice to apply */ around(base: GenericClass | ComposeFactory, method: string | symbol, advice: AroundAdvice): GenericFunction; around(method: GenericFunction, advice: AroundAdvice): GenericFunction; /** * Apply advice to methods that exist in the base factory using the supplied advice map * * @param base The Factory that contains the methods the advice will be applied to * @param advice The map of advice to be applied */ aspect(base: ComposeFactory, advice: AspectAdvice): ComposeFactory; } export interface ComposeFactory extends ComposeMixinable { /** * Create a new instance * * @param options Options that are passed to the initialization functions of the factory */ (options?: O): T; /** * The read only prototype of the factory */ readonly prototype: T; } export interface Compose { /** * Create a new factory based on a supplied Class, Factory or Object prototype with an optional * initalization function * * @param base The base Class, Factory or Object prototype to use * @param initFunction An optional function that will be passed the instance and any creation options * @param className An optional class name that is used to label the factory for debug purposes */ (className: string, base: ComposeFactory, initFunction?: ComposeInitializationFunction): ComposeFactory; (className: string, base: GenericClass | T, initFunction?: ComposeInitializationFunction): ComposeFactory; (base: ComposeFactory, initFunction?: ComposeInitializationFunction): ComposeFactory; (base: GenericClass | T, initFunction?: ComposeInitializationFunction): ComposeFactory; /** * Create a new factory based on a supplied Class, Factory or Object prototype with an optional * initialization function * * @param base The base Class, Facotry or Object prototype to use * @param initFunction An optional function that will be passed the instance and nay creation options */ create(className: string, base: ComposeFactory, initFunction?: ComposeInitializationFunction): ComposeFactory; create(className: string, base: GenericClass | T, initFunction?: ComposeInitializationFunction): ComposeFactory; create(base: ComposeFactory, initFunction?: ComposeInitializationFunction): ComposeFactory; create(base: GenericClass | T, initFunction?: ComposeInitializationFunction): ComposeFactory; } export interface ComposeFactory extends ComposeMixinable { /** * Add static properties to a factory * * @param staticProperties An object literal that contains methods and properties that should be "static" (e.g. added to * the factory, instead of the factory's prototype) */ static(staticProperties: S): this & S; } export interface Compose { /** * Add static properties to a factory * * @param staticProperties An object literal that contains methods and properties that should be "static" (e.g. added to * the factory, instead of the factory's prototype) */ static(factory: ComposeFactory, staticProperties: S): ComposeFactory & S; } export interface ComposeFactory extends ComposeMixinable { /** * The class name of the ComposeFactory */ readonly name?: string; } /** * A factory construction utility * * @param base An ES6 Class, ComposeFactory or Object literal to use as the base for the new factory * @param initFunction An optional initialization function for the factory */ declare const compose: Compose; export default compose;