import { Class } from "@agape/types"; /** * Describes a method and all associated modifiers and provides the * method dispatcher. */ export declare class MethodDescriptor { ʘafter: Array<(...args: any[]) => void>; ʘaround: Array<(...args: any[]) => void>; ʘbefore: Array<(...args: any[]) => void>; ʘdefault: (...args: any[]) => void; ʘoverride: (...args: any[]) => void; ʘstack: Array<(...args: any[]) => void>; ʘtransient: boolean; /** * Add a method to be called after the primary method * @param value Function or method to be called */ after(value: (...args: any[]) => void): this; /** * Add a method to be called before the primary method * @param value Function or method to be called */ before(value: (...args: any[]) => void): this; /** * Set the default value for the primary method. This is the primary * method which will be called, unless it has been over-ridden. * @param value */ default(value: (...args: any[]) => void): this; /** * Set the over-ride value for the primary method. This will be * called instead of the default value. */ override(value: (...args: any[]) => void): this; /** * Add a method to be called after the primary method but before * any after methods * @param value */ stack(value: (...args: any[]) => void): this; /** * Has a modified been set on the descriptor, returns true or false. * @param modifier */ does(modifier: string): boolean; /** * Execute the method and all method modifiers * @param target The object to call the method on * @param args The arguments to pass to the object */ call(target: unknown, ...args: any[]): unknown; /** * Call a stack of methods * @param modifier The name of the stack to execute * @param target The object on which to act * @param args The arguments to pass */ callStack(modifier: string, target: unknown, ...args: any[]): void; /** * Include the definitions from another method descriptor into this descriptor, * used to merge descriptors when applying traits to a class * @param from Descriptor to include */ include(from: MethodDescriptor): void; /** * Install the method dispatcher which handles calling of any modifiers * into the target object * @param target Target object to install the dispatcher * @param name Name of the method to replace */ installDispatcher(target: unknown, name: string): void; } /** * A set containing the managed methods that exist on an object. */ export declare class MethodDescriptorSet { private methods; constructor(from?: MethodDescriptorSet); /** * Merge descriptors from another set into this set * @param from */ merge(from: MethodDescriptorSet): void; /** * Does a descriptor with the given name exist in the set * @param name */ has(name: string): boolean; /** * Get a descriptor for the given name, creates a descriptor if * one does not exist. * @param name */ get(name: string): MethodDescriptor; /** * Get names of all descriptors which exist in the set. */ get names(): Array; /** * Set the descriptor for the given name * @param name * @param descriptor */ set(name: string, descriptor: MethodDescriptor): Map; /** * Execute a function on each item in the set * @param callback */ forEach(callback: (methodName: string, definition: MethodDescriptor) => void): void; } /** * Describes an object, holding information about methods, properties, and traits. */ export declare class ObjectDescriptor { target: object; methods: MethodDescriptorSet; properties: PropertyDescriptorSet; traits: Array; constructor(target: object); does(trait: Class): boolean; /** * Returns a PropertyDescriptor for the property with the given name. If * a descriptor does not exist for the property, one will be created for it * and the dispatcher will be installed to the object. * @param name R */ property(name: string): PropertyDescriptor; /** * Returns a MethodDescriptor the method with the given name. If a desriptor * does not exist for the method, one will be created for it and the dispatcher * will be created for it and the dispatcher will be installed to the object. */ method(name: string): MethodDescriptor; /** * Include traits the specified traits into the ObjectDescriptor, copying * over default method definitions and merging all property and method * descriptors as applicable. * @param traits */ include(...traits: Class[]): any; } /** * Property Dispatchers */ /** * Delegate 'get' property access to another object * @param $this PropertyDescriptor * @param instance Instance of the object to act on * @returns Value of the property on the delegated object */ declare function delegateGetDispatcher($this: PropertyDescriptor, instance: any): any; declare function readonlySetDispatcher($this: PropertyDescriptor, instance: any, value: any): void; /** * Describes the property of an object any associated modifiers. Provides * the property dispatcher. */ export declare class PropertyDescriptor { progenitor: ObjectDescriptor; name: string; ʘdelegate: { to?: any | ((instance: any) => any); property?: string; }; ʘdefault: any | ((instance: any) => any); ʘenumerable: boolean; ʘreadonly: boolean; ʘoverride: boolean; ʘinherit: { from?: any | ((instance: any) => any); property?: string; }; ʘlazy: boolean; /** * @param progenitor The object to which the property belongs * @param name The name of the property */ constructor(progenitor: ObjectDescriptor, name: string); /** * Delegate getting and setting of the property to that of another object * @param to The object to delegate the property to * @param property The name of the property to delegate to */ delegate(to: ((instance: any) => any) | any, property?: string): this; /** * Set default value for the property, can be a primitive value or a callback * function which returns any value type, such as a data structure or object * @param value Default value */ default(value: any): this; /** * By setting enumerable to false the property will not be included when * iterating over the properties of the object. The property will also * not be included when printing using console.log() * @param value True or false */ enumerable(value: boolean): this; /** * Readonly properties will throw an exception when attempting to set the value * @param value True or false */ readonly(value?: boolean): this; /** * Override the default value of the property * @param value */ override(value: any): this; /** * Include the definitions from another property descriptor into this descriptor, * used to merge descriptors when applying traits to a class * @param from Descriptor to include */ include(from: PropertyDescriptor): this; /** * Inherit the value from another object * @param from * @param property */ inherit(from: any | ((instance: any) => any), property?: string): this; /** * Initialize a property with the default value * @param instance The instance to act on * @returns */ initializeValue(instance: any): any; /** * A default value that will be instantiated the first time the property is accessed * @param value The default value for the property */ lazy(value?: any): this; /** * Get the value of the property on the given object, delegating or building * the property value as necessary * @param instance The object on which to act */ get(instance: any): any; /** * Set the value of the property on the given instance, delegating if needed * @param instance The object on which to act * @param value The new value */ set(instance: any, value: any): any; getSetDispatcher(): typeof readonlySetDispatcher; getGetDispatcher(): typeof delegateGetDispatcher; /** * Install the property dispatcher into the target object. The dispatcher handles * any property modifiers which have been applied. * @param target Target object to install the dispatcher * @param name Name of the method to replace */ installDispatcher(): void; } /** * A set containing the managed properties that exist on an object. */ export declare class PropertyDescriptorSet { progenitor: ObjectDescriptor; private properties; constructor(progenitor: ObjectDescriptor, from?: PropertyDescriptorSet); /** * Add a property to the set * @param property */ add(property: PropertyDescriptor): void; /** * Return all property descriptors in the set * @returns Array of PropertyDescriptor objects */ all(): PropertyDescriptor[]; /** * Merge descriptors from another set into this set * @param from */ merge(from: PropertyDescriptorSet): void; /** * Does a descriptor with the given name exist in the set * @param name */ has(name: string): boolean; /** * Get a descriptor for the given name, creates a descriptor if * one does not exist. * @param name */ get(name: string): PropertyDescriptor; /** * Get names of all descriptors which exist in the set. */ get names(): Array; /** * Set the descriptor of the given name * @param name * @param descriptor */ set(name: string, descriptor: PropertyDescriptor): Map; /** * Execute a function on each item in the set * @param callback */ forEach(callback: (propertyName: string, definition: PropertyDescriptor) => void): void; } export {};