import type { Injector } from './injector'; export declare type ConstructorOf = new (...args: any[]) => T; export declare type TokenResult = T extends ConstructorOf ? R : any; export declare type Token = string | symbol | Function; export declare type Tag = string | number; export declare type Domain = string | symbol; export declare const INJECTOR_TOKEN: Token; /** * Represents the state in this round of creating. */ export interface Context { injector: Injector; token: Token; creator: T; /** * Refers to the state of the last time in the recursive creation process */ parent?: Context; } export declare type TypeProvider = ConstructorOf; interface BasicProvider { token: Token; tag?: Tag; dropdownForTag?: boolean; isDefault?: boolean; override?: boolean; } /** * Provide a `class` that is used to instantiated */ export interface ClassProvider extends BasicProvider { useClass: ConstructorOf; } /** * Provide a `value` that is used to get */ export interface ValueProvider extends BasicProvider { useValue: any; } export interface AliasProvider extends BasicProvider { useAlias: Token; } export interface FactoryFunction { (injector: Injector): T; } export interface FactoryProvider extends BasicProvider { useFactory: FactoryFunction; } export declare type Provider = ClassProvider | TypeProvider | ValueProvider | AliasProvider | FactoryProvider; export declare enum CreatorStatus { init = 0, creating = 1, done = 2 } interface BasicCreator { tag?: Tag; dropdownForTag?: boolean; status?: CreatorStatus; /** * Store the instantiated objects. */ instances?: Set; /** * Represent this creator is parsed from `Parameter`. and the params of Inject has set `default` attribution. */ isDefault?: boolean; } export interface ValueCreator extends BasicCreator { status: CreatorStatus.done; } export interface ParameterOpts { token: Token; default?: any; } export interface ClassCreator extends BasicCreator { opts: InstanceOpts; parameters: ParameterOpts[]; useClass: ConstructorOf; } export interface FactoryCreator extends BasicCreator { useFactory: FactoryFunction; } export interface AliasCreator extends BasicCreator { useAlias: Token; } export declare type InstanceCreator = ValueCreator | ClassCreator | FactoryCreator | AliasCreator; export interface InstanceOpts { version?: string; multiple?: boolean; tag?: Tag; domain?: Domain | Domain[]; } export interface InjectorOpts { strict?: boolean; dropdownForTag?: boolean; tag?: string; } export interface AddProvidersOpts { override?: boolean; deep?: boolean; } export declare type MethodName = string | number | symbol; export declare enum HookType { Before = "Before", After = "After", Around = "Around", AfterReturning = "AfterReturning", AfterThrowing = "AfterThrowing" } export declare type IBeforeAspectHookFunction = (joinPoint: IBeforeJoinPoint) => void | Promise; export declare type IAfterAspectHookFunction = (joinPoint: IAfterJoinPoint) => void | Promise; export declare type IAroundAspectHookFunction = (joinPoint: IAroundJoinPoint) => void | Promise; export declare type IAfterReturningAspectHookFunction = (joinPoint: IAfterReturningJoinPoint) => void | Promise; export declare type IAfterThrowingAspectHookFunction = (joinPoint: IAfterThrowingJoinPoint) => void | Promise; export declare type IAspectHookTypeFunction = IBeforeAspectHookFunction | IAfterAspectHookFunction | IAroundAspectHookFunction | IAfterReturningAspectHookFunction | IAfterThrowingAspectHookFunction; export declare type IInstanceHooks = Map; export declare type IHookMap = Map; /** * Describe how to hook a method */ export interface IAspectHook { target: Token; method: MethodName; awaitPromise?: boolean; priority?: number; type: HookType; hook: IAspectHookTypeFunction; } export declare type IValidAspectHook = IBeforeAspectHook | IAfterAspectHook | IAroundAspectHook | IAfterReturningAspectHook | IAfterThrowingAspectHook; export interface IBeforeAspectHook extends IAspectHook { type: HookType.Before; hook: IBeforeAspectHookFunction; } export interface IAfterAspectHook extends IAspectHook { type: HookType.After; hook: IAfterAspectHookFunction; } export interface IAfterReturningAspectHook extends IAspectHook { type: HookType.AfterReturning; hook: IAfterReturningAspectHookFunction; } export interface IAroundAspectHook extends IAspectHook { type: HookType.Around; hook: IAroundAspectHookFunction; } export interface IAfterThrowingAspectHook extends IAspectHook { type: HookType.AfterThrowing; hook: IAfterThrowingAspectHookFunction; } export interface IJoinPoint { getThis(): ThisType; getMethodName(): MethodName; getOriginalArgs(): Args; } export interface IBeforeJoinPoint extends IJoinPoint { getArgs(): Args; setArgs(args: Args): void; } export interface IAfterJoinPoint extends IJoinPoint { getArgs(): Args; getResult(): Result; setResult(result: Result): void; } export interface IAroundJoinPoint extends IJoinPoint { getArgs(): Args; setArgs(args: Args): void; getResult(): Result; setResult(result: Result): void; proceed(): Promise | void; } export interface IAfterReturningJoinPoint extends IJoinPoint { getArgs(): Args; getResult(): Result; } export interface IAfterThrowingJoinPoint extends IJoinPoint { getError(): Error | undefined; } export interface IHookStore { createHooks(hooks: IValidAspectHook[]): IDisposable; createOneHook(hook: IValidAspectHook): IDisposable; removeOneHook(hook: IValidAspectHook): void; getHooks(token: Token, method: MethodName): IValidAspectHook[]; hasHooks(token: Token): boolean; } export interface IDisposable { dispose: () => void; } export interface IHookOptions { /** * Whether to wait for the hook (if the return value of the hook is a promise) */ await?: boolean; /** * The priority of the hook. * for `before` hooks, the higher the priority, the earlier the execution. * for `after` and `around` hooks, the higher the priority, the later the execution. * @default 0 */ priority?: number; } export interface IAroundHookOptions extends IHookOptions { /** * @deprecated around hooks act as the union model, you can just use `ctx.proceed()`(no await) to invoke the next hook. */ await?: boolean; } export {};