UNPKG

@discordx/internal

Version:
136 lines (131 loc) 5.17 kB
/** * Represents a base decorator class. * @category Decorator */ declare class Decorator { protected _classRef: Record<string, any>; protected _from: Record<string, any>; protected _key: string; protected _method?: Record<string, any>; protected _index?: number; /** * Gets the index of the parameter being decorated, if applicable. */ get index(): number | undefined; /** * Gets or sets the class reference being decorated. */ get classRef(): Record<string, any>; set classRef(value: Record<string, any>); /** * Gets or sets the originating class reference. */ get from(): Record<string, any>; set from(value: Record<string, any>); /** * Gets the key of the property or method being decorated. */ get key(): string; /** * Gets the method descriptor if the target is a method. */ get method(): Record<string, any> | undefined; /** * Determines if the target is a class. */ get isClass(): boolean; /** * Decorates an unknown type (class, method, or property). * @param classRef - The class reference. * @param key - The property key. * @param method - The method descriptor. * @param index - The parameter index. * @returns The current instance. */ decorateUnknown(classRef: Record<string, any>, key?: string, method?: PropertyDescriptor, index?: number): this; /** * Applies the decoration to the specified target. * @param classRef - The class reference. * @param key - The property key. * @param method - The method descriptor. * @param from - The originating class reference. * @param index - The parameter index. * @returns The current instance. */ decorate(classRef: Record<string, any>, key: string, method?: Record<string, any>, from?: Record<string, any>, index?: number): this; } type ModifyFunction<ToModify extends Decorator> = (original: ToModify) => unknown; type Constructor<T extends Decorator> = new (...args: any[]) => T; /** * Represents a modifier for decorators. * @category Internal */ declare class Modifier<ToModify extends Decorator = Decorator> extends Decorator { private _toModify; private _modifyTypes; /** * Constructor to initialize a modifier. * @param toModify - The function to modify the decorator. * @param modifyTypes - The list of types that can be modified. */ constructor(toModify: ModifyFunction<ToModify>, modifyTypes: Constructor<ToModify>[]); /** * Creates a new modifier instance. * @param toModify - The function to modify the decorator. * @param modifyTypes - The list of types that can be modified. * @returns A new modifier instance. */ static create<ToModifyEx extends Decorator>(toModify: ModifyFunction<ToModifyEx>, ...modifyTypes: Constructor<ToModifyEx>[]): Modifier<ToModifyEx>; /** * Applies the modifications from a list of modifiers to a list of decorators. * @param modifiers - The list of modifiers. * @param originals - The list of decorators to modify. * @returns A promise that resolves when all modifications are applied. */ static applyFromModifierListToList(modifiers: Modifier[], originals: Decorator[]): Promise<void>; /** * Applies modifications to the specified decorator. * @param original - The decorator to modify. * @returns The result of the modification function. */ applyModifications(original: ToModify): unknown; } /** * Gets the list of decorators linked to a specified decorator. * @example * ```typescript * @A() * @B() * method() {} * ``` * @example * ```typescript * method( * @A() * @B() * param: string * ) {} * ``` * @example * ```typescript * @A() * @B() * class X {} * ``` * @param a - The reference decorator. * @param list - The list of decorators to filter. * @returns The list of linked decorators. */ declare function getLinkedObjects<Type extends Decorator>(a: Decorator, list: Type[]): Type[]; /** * Determines if the target is a class based on the method descriptor. * @param method - The method descriptor. * @returns True if the target is a class, false otherwise. */ declare function decorateAClass(method?: PropertyDescriptor): boolean; type ClassDecoratorEx = (target: Record<string, any>, propertyKey?: undefined, descriptor?: undefined) => void; type PropertyDecorator = (target: Record<string, any>, propertyKey: string, descriptor?: undefined) => void; type MethodDecoratorEx = <T>(target: Record<string, any>, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void; type ParameterDecoratorEx = (target: Record<string, any>, propertyKey: string, parameterIndex: number) => void; type ClassMethodDecorator = <T>(target: Record<string, any>, propertyKey?: string, descriptor?: TypedPropertyDescriptor<T>) => void; export { type ClassDecoratorEx, type ClassMethodDecorator, type Constructor, Decorator, type MethodDecoratorEx, Modifier, type ModifyFunction, type ParameterDecoratorEx, type PropertyDecorator, decorateAClass, getLinkedObjects };