export interface Constructor { new (...args: any[]): T; prototype: T; } export interface AbstractType { prototype: T; } /** 用来区分范围的id,范围注入依赖于这个id来实现 */ export declare type ScopeID = string | Symbol; /** 描述一个类型的变量一定不为undefined */ export declare type Exist = Exclude; /** 描述一个必不为undefined的变量是可能为null的 */ export declare type Nullable = Exist | null; /** Built-in metadata type: context type of the record attribute method */ export declare const TYPE_META_KEY = "design:type"; /** Built-in metadata type: params types of the record attribute method */ export declare const PARAMS_META_KEY = "design:paramtypes"; /** Built-in metadata type: return type of the record attribute method */ export declare const RETURN_META_KEY = "design:returntype"; /** * 描述了依赖项在整个容器中的生命周期情况 * @description * @export * @enum {number} */ export declare enum InjectScope { Singleton = 0, Scope = 1, New = 2 } export interface IBaseInjectable { __valid?: boolean; } export declare type InjectableToken = AbstractType; /** * 描述一个实现类型的构造函数 * @description * @author Big Mogician * @export * @interface ImplementType * @template T */ export interface ImplementType { prototype?: T; } export declare type ImplementToken = ImplementType; export declare type IInjectable = Constructor; /** 依赖注入项基础构造工厂 */ export declare type ImplementBasicFactory = (scopeId?: SCOPE, scopeData?: ScopeMetadata) => T; interface IArrayLike { [Symbol.iterator]: any; [Symbol.unscopables]: any; } declare type ConstructorsTuple = IArrayLike & { [key in keyof T]: T[key] extends Constructor ? TV : any; }; export declare type IResolvableFactory = (...depts: DEPTS) => T; /** 依赖注入项构造工厂 */ export declare type IDeptFactory[] = [], CONTEXT = any> = IResolvableFactory> | ImplementBasicFactory; export declare type InjectDIToken = Constructor | AbstractType; export declare type InjectToken = InjectDIToken; export declare type ImplementBasicDIValue = ImplementType | T | ImplementBasicFactory; export declare type ImplementDIValue = ImplementType | T | IResolvableFactory; export declare type Implement = ImplementBasicDIValue | ImplementDIValue; export interface IToken { key: symbol; } export interface IEntry { token: IToken; value: T; } export declare type ITokenGenerator = (key: string) => IToken; export interface ConfigsCollection { get(token: IToken): T; } export interface IConfigCollection extends ConfigsCollection { set(token: IToken, entry: T): void; toArray(): IEntry[]; } export interface DIEntry { getInstance(): T; } export interface ReadonlyDIContainer { get(token: InjectToken, scopeId?: ID): T; } export declare type ScopeMetadata = SCOPE & { readonly scopeId: ID; }; export interface IRegisterConfig { token: InjectToken; imp: Implement; scope: InjectScope; depts?: DEPTS; } export interface IDIContainer extends ReadonlyDIContainer { count: number; register(config: IRegisterConfig): void; getDepedencies(depts: InjectToken[], scopeId?: ID): any[]; getConfig(): any; complete(): void; createScope(scopeId: ID, metadata: SCOPE): void; dispose(scopeId?: ID): void; } /** * 在依赖注入容器内部正常运作所需要提供的entry信息 * @description * @author Big Mogician * @export * @interface DepedencyResolveEntry * @template T */ export interface DepedencyResolveEntry { /** 注入令牌 */ token: InjectToken; /** 实现 */ imp: any; /** 依赖的其他令牌数组 */ depts: InjectToken[]; /** React-Singleton依赖令牌数组 */ watch: [string, InjectToken][]; /** 注入项的生命周期和解析范围 */ scope: InjectScope; } /** * 依赖注入容器内部entry的完整信息 * @description * @author Big Mogician * @export * @interface DIContainerEntry * @extends {DepedencyResolveEntry} * @template T */ export interface DIContainerEntry extends DepedencyResolveEntry { /** 工程方法,手工提供或者由框架生成 */ fac: Nullable>; /** 包裹处理scope之后的工程方法,是解析依赖项的最终执行方法 */ getInstance: Nullable<(scopeId?: ScopeID) => T | null>; /** 当前依赖项的依赖层级,高级依赖低级 */ level: number; /** 注入的历史,包含所有覆盖行为的操作栈 */ history: DepedencyResolveEntry[]; } export interface IToken { key: symbol; } export interface IEntry { token: IToken; value: T; } export declare type EmitType = "info" | "error" | "warn"; interface EmitPayload { level: EmitType; data: { msg: string; [prop: string]: any; }; error?: Error; } export interface IContainerConfigs { type: "native" | "proxy"; onEmit?: (e: EmitPayload) => void; throws?: boolean; } export interface IProxyBundle { init: boolean; source: T; } export {};