import { ConstructorType as ConstructorType$1, Prototype, MethodPropertyDescriptor } from '@aspectjs/common/utils'; /** * An annotation is identified by its name and its group id. * An AnnotationRef represents the identity of an annotation. */ declare class AnnotationRef { private static readonly registry; /** * The value of the annotation reference. */ readonly value: string; /** * The name of the referenced annotation. */ readonly name: string; /** * The group id of the referenced annotation. */ readonly groupId: string; /** * @internal * @param ref */ private constructor(); /** * @internal * @param groupId * @param name */ private constructor(); /** * Get the string representation of the annotation in the format: `@:` * @returns The string representation of the annotation. */ toString(): string; /** * Create a new Annotation Reference out of an Annotation, a string, or an AnnotationRef. * @param obj * @returns */ static of(groupId: string, name: string): AnnotationRef; static of(obj: Pick | string): AnnotationRef; private static register; private static get; } /** * Type of an annotation. */ declare enum AnnotationKind { CLASS = 1, PROPERTY = 2, METHOD = 4, PARAMETER = 8 } /** * @internal */ type ClassDecorator = (target: TFunction) => TFunction; /** * @internal */ type MethodDecorator = (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; /** * @internal */ type AnnotationStub = (...args: any[]) => Decorator | void; /** * An Annotation is an EcmaScript decorator with no behavior. * It is identified by a name and a group ID. * * @typeParam T - The type of the annotation, derived from `AnnotationKind`. * @typeParam S - The type of the annotation stub, derived from `AnnotationStub`. */ type Annotation = AnnotationStub> = { /** * The reference to the annotation */ ref: AnnotationRef; } & { /** * The name of the annotation. */ readonly name: string; /** * The group ID of the annotation. */ readonly groupId: string; } & ((...args: Parameters) => Decorator); /** * @internal */ type Decorator = T extends AnnotationKind.CLASS ? ClassDecorator : T extends AnnotationKind.METHOD ? MethodDecorator : T extends AnnotationKind.PARAMETER ? ParameterDecorator : T extends AnnotationKind.PROPERTY ? PropertyDecorator : any; /** * @internal */ type AnyDecorator = ClassDecorator & MethodDecorator & ParameterDecorator & PropertyDecorator; interface BoundClassAnnotationTarget extends ClassAnnotationTarget { eval(): X; } interface BoundParameterAnnotationTarget extends ParameterAnnotationTarget { eval(): unknown; } interface BoundMethodAnnotationTarget extends MethodAnnotationTarget { eval(): (...args: unknown[]) => unknown; } interface BoundPropertyAnnotationTarget extends PropertyAnnotationTarget { eval(): unknown; } /** * Represents the symbol (Class, Method, Parameter, Property) annotated by an annotation. * This symbol is bound to an actual instance, and has a "value" attribute. * @param T The kind of annotation * @param X The type of the class that target belongs to. */ type BoundAnnotationTarget = T extends AnnotationKind.CLASS ? BoundClassAnnotationTarget : T extends AnnotationKind.PARAMETER ? BoundParameterAnnotationTarget : T extends AnnotationKind.METHOD ? BoundMethodAnnotationTarget : T extends AnnotationKind.PROPERTY ? BoundPropertyAnnotationTarget : never; /** * Create {@link AnnotationTarget} */ declare class AnnotationTargetFactory { of(target: ConstructorType$1): AnnotationTarget; of(target: X): BoundAnnotationTarget; of(target: ConstructorType$1, propertyKey: keyof X): AnnotationTarget; of(target: X, propertyKey: keyof X): BoundAnnotationTarget; of(target: ConstructorType$1, propertyKey: keyof X, descriptor: PropertyDescriptor): AnnotationTarget; of(target: X, propertyKey: keyof X, descriptor: PropertyDescriptor): BoundAnnotationTarget; of(target: ConstructorType$1, propertyKey: keyof X, parameterIndex: number): AnnotationTarget; } declare function inferTypeFromArgs(...args: unknown[]): AnnotationKind; declare function inferTypeFromArgs(decoree: ConstructorType$1 | Prototype, propertyKey?: string | symbol, parameterIndex?: number, descriptor?: PropertyDescriptor): AnnotationKind; declare class _AnnotationContextSet { private buckets; getAnnotations(decoratorTypes: AnnotationKind[], annotationRefs?: Set, classTargetRef?: AnnotationTargetRef | undefined, propertyKey?: string | number | symbol | undefined): AnnotationContext[]; addAnnotation(ctxt: AnnotationContext): void; } interface BoundAnnotationContext extends AnnotationContext { readonly target: BoundAnnotationTarget; } interface AnnotationSelectorOptions { /** * Search for the annotation in parent classes. */ searchParents: boolean; } declare class AnnotationsSelector { private readonly targetFactory; private readonly annotationSet; private readonly annotationsRefs; private readonly decoratorTypes; private readonly type?; private readonly propertyKey?; private readonly parameterIndex?; constructor(selector: AnnotationsSelector); constructor(targetFactory: AnnotationTargetFactory, annotationSet: _AnnotationContextSet, annotationsRefs: Set | undefined, decoratorTypes: T[], type?: ConstructorType$1 | X, propertyKey?: string | symbol, parameterIndex?: number); find(options?: AnnotationSelectorOptions): AnnotationContext[]; } declare class BoundAnnotationsSelector extends AnnotationsSelector { private instance; private args?; constructor(selector: AnnotationsSelector, instance: unknown, args?: unknown[] | undefined); find(options?: AnnotationSelectorOptions): BoundAnnotationContext[]; } /** * @internal */ declare class AnnotationTargetRef { readonly value: string; constructor(value: string); toString(): string; } /** * @internal */ interface BaseAnnotationTarget { readonly kind: T; readonly proto: Prototype; readonly name: string; readonly label: string; readonly ref: AnnotationTargetRef; readonly declaringClass: ClassAnnotationTarget; readonly parentClass: ClassAnnotationTarget | undefined; readonly static: boolean; asDecoratorArgs(): any[]; eval(): unknown; defineMetadata(key: string, value: any): void; getMetadata(key: string, defaultvalue: () => T): T; getMetadata(key: string, defaultvalue?: () => T): T | undefined; annotations(annotation: S): AnnotationsSelector; annotations(...annotation: Annotation[]): AnnotationsSelector; } /** * Target for an annotated class. * @param X the type of the class */ interface ClassAnnotationTarget extends BaseAnnotationTarget { readonly parentClass: ClassAnnotationTarget | undefined; readonly static: boolean; } /** * Target for an annotated property. * @param X the type of the property's class */ interface PropertyAnnotationTarget extends BaseAnnotationTarget { readonly propertyKey: string | symbol; readonly declaringClass: ClassAnnotationTarget; readonly descriptor?: TypedPropertyDescriptor; readonly static: boolean; } /** * Target for an annotated method. * @param X the type of the method's class */ interface MethodAnnotationTarget extends BaseAnnotationTarget { readonly propertyKey: string | symbol; readonly descriptor: MethodPropertyDescriptor; readonly declaringClass: ClassAnnotationTarget; readonly static: boolean; } /** * Target for an annotated parameter. * @param X the type of the parameter's class */ interface ParameterAnnotationTarget extends BaseAnnotationTarget { readonly propertyKey: string | symbol; readonly parameterIndex: number; readonly descriptor: MethodPropertyDescriptor; readonly declaringMethod: MethodAnnotationTarget; readonly declaringClass: ClassAnnotationTarget; readonly static: boolean; } /** * Represents the symbol (Class, Method, Parameter, Property) annotated by an annotation. * @param T The kind of annotation * @param X The type of the class that target belongs to. */ type AnnotationTarget = T extends AnnotationKind.CLASS ? ClassAnnotationTarget : T extends AnnotationKind.PARAMETER ? ParameterAnnotationTarget : T extends AnnotationKind.METHOD ? MethodAnnotationTarget : T extends AnnotationKind.PROPERTY ? PropertyAnnotationTarget : never; /** * Holds data about the execution context where the annotation is being invoked. */ declare class AnnotationContext { /** * The arguments passed to the annotation. */ readonly args: Parameters; /** * The target of the annotation. */ readonly target: AnnotationTarget; /** * The reference to the annotation being invked. */ readonly ref: AnnotationRef; /** * @param ref @internal */ constructor( /** * The annotation, or its reference, that is being invoked. */ ref: Annotation | AnnotationRef, /** * The arguments passed to the annotation. */ args: Parameters, /** * The target of the annotation. */ target: AnnotationTarget); /** * * @returns The signature of the annotation, in the form `@: on `. */ toString(): string; } type AnnotationSelectionFilter = { target: AnnotationTarget; /** * Which kind of annotation to select ? */ types?: AnnotationKind[]; }; /** * Selects annotations based on their type or target. */ declare class AnnotationByTargetSelector { private readonly targetFactory; private readonly annotationSet; private readonly annotationsRefs; constructor(targetFactory: AnnotationTargetFactory, annotationSet: _AnnotationContextSet, annotationsRefs: Set | undefined); all(type?: ConstructorType$1): AnnotationsSelector; all(type?: X): BoundAnnotationsSelector; onClass(type?: ConstructorType$1): AnnotationsSelector; onClass(type?: X): BoundAnnotationsSelector; onMethod(type?: ConstructorType$1 | X, propertyKey?: K): AnnotationsSelector; onProperty(type?: ConstructorType$1, propertyKey?: K): AnnotationsSelector; onProperty(type?: X, propertyKey?: K): BoundAnnotationsSelector; onParameters(type?: ConstructorType$1 | X, propertyKey?: K): AnnotationsSelector; onParameter(type: ConstructorType$1 | X, propertyKey: K, parameterIndex: number): AnnotationsSelector; private createSelector; on(filter: AnnotationSelectionFilter): AnnotationsSelector; } declare function getAnnotations(annotation: S): AnnotationByTargetSelector; declare function getAnnotations(...annotations: (Annotation | AnnotationRef | string)[]): AnnotationByTargetSelector; /** * Store all registered annotations */ declare class AnnotationContextRegistry { private targetFactory; private readonly annotationSet; constructor(targetFactory: AnnotationTargetFactory); register(annotationContext: AnnotationContext): void; select(...annotations: (Pick | Annotation | string)[]): AnnotationByTargetSelector; } interface AnnotationsByTypeSelectionOptions { /** * Search for the annotation in parent classes. */ searchParents: boolean; } declare class AnnotationsByRefSelector { private readonly targetFactory; private readonly annotationSet; private readonly annotationsRefs; private readonly decoratorTypes; private readonly type?; private readonly propertyKey?; constructor(selection: AnnotationsByRefSelector); constructor(targetFactory: AnnotationTargetFactory, annotationSet: _AnnotationContextSet, annotationsRefs: Set | undefined, decoratorTypes: T[], type?: ConstructorType$1 | X, propertyKey?: string | symbol); annotations(annotation: Annotation): AnnotationsSelector; annotations(...annotations: (AnnotationRef | Annotation)[]): AnnotationsSelector; find(options?: AnnotationsByTypeSelectionOptions): AnnotationContext[]; } /** * Options given to decoree.annotations {@link AnnotationFactory} to create a new annotation. * @typeParam T the type of annotation to create * @typeParam S the signature of the annotation to create. It defines the name of the annotation and the set of accepted parameters. */ interface AnnotationCreateOptions { /** * The name of the annotation to create. */ name: string; /** * The type of annotation to create. */ kind: T; } /** * Factory to create an {@link Annotation}. */ declare class AnnotationFactory { /** * The group of this factory. * All annotations created by this factory will belong to this group. */ readonly groupId: string; /** * Create a new AnnotationFactory with the given `groupId`. * You generaly have to choose a `groupId` that identifies your project or is unique to your organisation. * The `groupId` will be used as a part of the signature for the created annotations. * @param groupId The groupId of this factory. */ constructor( /** * The group of this factory. * All annotations created by this factory will belong to this group. */ groupId: string); /** * Create with the a n annotation. * @param options The options for the annotation to create. * @param annotationStub The signature of the annotation to create. * @typeParam T the type of annotation to create * @typeParam S the signature of the annotation to create. It defines the name of the annotation and the set of accepted parameters. */ create>(options?: AnnotationCreateOptions, annotationStub?: S): Annotation; /** * Create a new annotation with the given `name` and `type`. * If no annotation type is given, the annotation could be used above classes, methods, properties, attributes and parameters. * * @param name The name of the annotation to create. * @typeParam S the signature of the annotation to create. It defines the name of the annotation and the set of accepted parameters. * @example * ```ts * const LogErrors = new AnnotationFactory('demo').create('LogErrors'); * ``` */ create(name: string): Annotation; /** * Create a new annotation wwith the given type and signature. The created annotation accepts the same parameters as with the the provid function. * If no annotation type is given, the annotation could be used above classes, methods, properties, attributes and parameters. * * @param type The type of annotation to create. * @param name The name of the annotation to create. * @param annotationStub The signature of the annotation to create. * @typeParam T the type of annotation to create * @typeParam S the signature of the annotation to create. It defines the name of the annotation and the set of accepted parameters. * @example * ```ts * const LogErrors = new AnnotationFactory('demo').create( * AnnotationKind.METHOD, * 'Log', * function Log( * level: 'info' | 'warn' | 'error' | 'debug' = 'error', * ) {}); * ``` */ create>(type: T, name?: string, annotationStub?: S): Annotation; /** * Create a new annotation with the given signature. * The created annotation has the same name as the given function, and accepts the same parameters. * If no annotation type is given, the annotation could be used above classes, methods, properties, attributes and parameters. * * @param name The name of the annotation to create. * @param annotationStub The signature of the annotation to create. * @typeParam S the signature of the annotation to create. It defines the name of the annotation and the set of accepted parameters. * @example * ```ts * const LogErrors = new AnnotationFactory('demo').create( * 'Log', * function Log( * level: 'info' | 'warn' | 'error' | 'debug' = 'error', * ) {}); * ``` */ create(name?: string, annotationStub?: S): Annotation; private _createDecorator; private _createAnnotationContext; private _createAnnotation; } /** * @internal * Type provided by a ReflectProvider */ type ReflectProviderType = ConstructorType$1 & { __providerName?: string; }; /** * @internal * Provide a service to the Reflect Context */ type ReflectProvider = { deps?: (ConstructorType$1 | string)[]; provide: ReflectProviderType | string; factory: (...args: any[]) => T; }; /** * @internal * * The ReflectContext is a container for the global values and services of the framework. * The services are added to the context in the form of {@link ReflectProvider}s, * through the use of {@link ReflectModuleConfiguration}s. */ declare class ReflectContext { protected providersToResolve: Map; protected providersRegistry: Map; protected addedProviders: Set; protected modules: Set; /** * @internal * @param context */ constructor(context?: ReflectContext); /** * Adds a module to the context. Modules are unique by their name. * Adding the same module twice has no effect. * @param module The module to add */ registerModules(...modules: ConstructorType$1[]): ReflectContext; private addProviders; /** * Get a provider by its name or type. * @param provider The provider name or type. * @param T the provider type * @return The provider, if registered, undefined otherwise. */ get(providerType: ReflectProvider['provide']): T; private _get; /** * Know if a provider is registered. * @param providerType The provider name or type. * @param T the provider type * @returns true if the provider is registered, false otherwise. */ has(providerType: ReflectProvider['provide']): boolean; protected assign(context: ReflectContext): this; private _tryResolveProvider; } /** * @internal * A DecoratorHook is a configuration for the {@link AnnotationFactory} * to create typescript decorators that corresponds to a given annotation. */ type DecoratorHook = AnnotationStub> = { createDecorator: (reflect: ReflectContext, context: AnnotationContext, annotationStub: S) => Decorator | void; order?: number; name: string; }; /** * @internal */ declare class DecoratorHookRegistry { protected readonly hooks: Map; static readonly __providerName = "DecoratorHookRegistry"; values(): IterableIterator; add(annotationsHook: DecoratorHook): this; remove(annotationsHook: DecoratorHook | string): this; } declare const BOUND_INSTANCE_SYMBOL: unique symbol; declare const BOUND_VALUE_SYMBOL: unique symbol; /** * @internal */ declare abstract class _AnnotationTargetImpl implements BaseAnnotationTarget { readonly kind: T; readonly proto: Prototype; readonly name: string; readonly label: string; readonly ref: AnnotationTargetRef; abstract readonly declaringClass: ClassAnnotationTarget; abstract readonly parentClass: ClassAnnotationTarget | undefined; protected readonly [BOUND_INSTANCE_SYMBOL]?: X; protected readonly [BOUND_VALUE_SYMBOL]?: unknown; readonly ['static']: boolean; eval(): unknown; constructor(kind: T, proto: Prototype, name: string, label: string, ref: AnnotationTargetRef, staticAttribute?: boolean); annotations(annotation: S): AnnotationsSelector; annotations(...annotation: (Annotation | AnnotationRef | string)[]): AnnotationsSelector; abstract asDecoratorArgs(): any[]; abstract defineMetadata(key: string, value: any): void; abstract getMetadata(key: string, defaultvalue?: (() => T) | undefined): T | undefined; toString(): string; /** * Binds a value to this AnnotationTarget. The value is either the class instance for ClassAnnotationTarget, the property value for PropertyAnnotationTarget, MethodAnnotationTarget or ParameterAnnotationTarget. * In addition, in case of ParameterAnnotationTarget, the bind() method accepts a 2nd argument to bind the parameter value. * * @param instance The class instance to bind this target to. * @param value the value of this target */ abstract _bind(instance: X, args?: unknown[]): AnnotationTarget; } /** * @internal */ type AbstractConstructorType = abstract new (...args: any[]) => X; type ConcreteConstructorType = new (...value: any[]) => X; type ConstructorType = ConcreteConstructorType | AbstractConstructorType; interface AbstractToken { readonly template?: T | ConstructorType; } /** * Disables errors when calling ${@link abstract} method. * @param receipe the function to be executed without throwing an error in case ${@link abstract} method is called. * @returns */ declare const _defuseAbstract: (receipe: () => unknown) => unknown; /** * Annotating abstract methods is not allowed in TypeScript. * Instead, we have to define concrete, empty methods, awaiting for an annotation to actually define its behaviour. * However, typescript will throw a compilation error if that method declares a return value but the body is empty. * The abstract function is a placeholder that stands for a return value. * It will throw if called as is, but it is intended to be bypassed by the action of an annotation. * * @param T the type of the value to be replaced. */ declare function abstract(): T; declare function abstract(template: [ConstructorType]): T[]; declare function abstract(template: ConstructorType): T; declare function abstract(template: T): T; declare const isAbstractToken: (val: any) => boolean; interface ReflectModuleConfiguration { providers: ReflectProvider[]; } declare const ReflectModule: (config: ReflectModuleConfiguration) => (target: any) => any; /** * Get the reflect context. * @internal * @returns The reflect context. */ declare const reflectContext: () => ReflectContext; /** * @internal * Replace the current reflect context. Internally called by {@link ./../../testing/src/setup#configureTesting} * @param context * @returns */ declare const _setReflectContext: (context: ReflectContext) => ReflectContext; declare class ReflectError extends Error { } export { type AbstractToken, type Annotation, AnnotationByTargetSelector, AnnotationContext, AnnotationContextRegistry, type AnnotationCreateOptions, AnnotationFactory, AnnotationKind, AnnotationRef, type AnnotationSelectorOptions, type AnnotationStub, type AnnotationTarget, AnnotationTargetFactory, AnnotationTargetRef, AnnotationsByRefSelector, type AnnotationsByTypeSelectionOptions, AnnotationsSelector, type AnyDecorator, BOUND_INSTANCE_SYMBOL, BOUND_VALUE_SYMBOL, type BaseAnnotationTarget, type BoundAnnotationContext, type BoundAnnotationTarget, BoundAnnotationsSelector, type BoundClassAnnotationTarget, type ClassAnnotationTarget, type Decorator, type DecoratorHook, DecoratorHookRegistry, type MethodAnnotationTarget, type ParameterAnnotationTarget, type PropertyAnnotationTarget, ReflectContext, ReflectError, ReflectModule, type ReflectModuleConfiguration, type ReflectProvider, type ReflectProviderType, _AnnotationTargetImpl, _defuseAbstract, _setReflectContext, abstract, getAnnotations, inferTypeFromArgs, isAbstractToken, reflectContext };