UNPKG

2.67 kBTypeScriptView Raw
1import { HashMap } from "@azera/util/is";
2export { HashMap };
3export declare type Service = IDefinition | Function | any[];
4export declare type Factory<T = {}> = Constructor<IFactory<T>> | FunctionOf<T>;
5export declare type ContainerValue = any;
6export declare type Constructor<T = {}> = new (...args: any[]) => T;
7export interface IInjectable extends Function {
8 $inject?: string[];
9}
10export declare type MockMethod<O extends object, K extends keyof O> = (...params: any[]) => ReturnType<O[K] extends ((...params: any[]) => any) ? O[K] : any>;
11export declare type MockMethodAsync<O extends object, K extends keyof O> = (...params: any[]) => Promise<ReturnType<O[K] extends ((...params: any[]) => any) ? O[K] : any>>;
12export declare type InjectableFunction<T = any> = {
13 (...params: any[]): T;
14 $inject?: string[];
15};
16export declare type FunctionOf<T> = (...params: any[]) => T;
17export declare type Injectable<T = any> = InjectableFunction<T> | Function | Array<string | Function | FunctionOf<T>>;
18export declare type InvokableFunctions<T> = Injectable<T> | Constructor<T> | Factory<T>;
19export declare type Invokable<T> = InvokableFunctions<T> | string | T;
20export declare type IServices = HashMap<IDefinition | Function | any[]>;
21export interface IAutoTagger {
22 (service: IDefinition): string[];
23}
24export declare type ServiceDefinitionCollection = HashMap<Service>;
25export interface IContainer {
26 set(values: {
27 [name: string]: IDefinition | ContainerValue;
28 }[]): this;
29 set(name: string, value: IDefinition | ContainerValue): this;
30 get<T>(name: string): T | undefined;
31 invoke<T>(value: Invokable<T>): T | undefined;
32}
33export interface IDefinition<T = Function> {
34 name: string;
35 service?: T;
36 parameters: (string | Function)[];
37 properties: HashMap<string | Function | IPropertyInjection>;
38 methods: {
39 [name: string]: (string | Function)[];
40 };
41 calls: {
42 [name: string]: (string | Function)[];
43 };
44 private: boolean;
45 isFactory: boolean;
46 factory?: Function | IFactory;
47 tags: string[];
48 invoke: boolean;
49 imports: (string | Function)[];
50 autoTags: ({
51 class: Function;
52 tags: string[];
53 } | IAutoTagger)[];
54}
55export interface IInternalDefinition extends IDefinition {
56 compiled?: boolean;
57 inherited?: boolean;
58 $target?: Function;
59}
60export interface IPropertyInjection {
61 lateBinding?: boolean;
62 name?: string | Function;
63}
64export interface IFactory<T = any> {
65 create(...params: any[]): T;
66}
67export interface IMethod {
68 context: any;
69 method: string;
70}