UNPKG

3.87 kBTypeScriptView Raw
1import Config from '../config/ConfigProvider';
2import { Logger } from '../log/LogManager';
3import { Lifecycle } from './Lifecycle';
4import { ObjectDefinition } from './objectdefinition/ObjectDefinition';
5import { ObjectDefinitionInspector } from './ObjectDefinitionInspector';
6/**
7 * A context used by IoC to register and request objects from.
8 * This is the main class for the inversion of control framework. It serves as a registry where you can
9 * add {ObjectDefinition}s and request instances from them.
10 */
11export interface ContextOptions {
12 logger?: Logger;
13 config?: Config;
14 shutdownTimer?: number;
15}
16export declare class Context extends Lifecycle {
17 private objectDefinitionInspector;
18 private startedObjects;
19 private objectDefinitions;
20 private parentContext;
21 private config;
22 private objectGroups;
23 private shutdownTimer;
24 constructor(name: string, parentContext?: Context, options?: ContextOptions);
25 lcStart(): Promise<void>;
26 lcStop(): Promise<void>;
27 protected doStart(): Promise<void>;
28 protected doStop(): Promise<any>;
29 clone(name: any): Context;
30 importContext(otherContext: any, overwrite?: boolean): void;
31 addObjectDefinitionInspector(inspector: ObjectDefinitionInspector): void;
32 registerDefinition(objectDefinition: ObjectDefinition<any>, overwrite?: boolean): void;
33 registerSingletons(...singletons: any[]): void;
34 registerSingletonsInDir(patterns: any, options: any): void;
35 static requireFilesInDir(dir: any): void;
36 /**
37 * Walks a directory recursively and returns an array with all the files
38 *
39 * @private
40 * @param dir The directory to walk through
41 * @param filelist The carried-over list of files
42 * @return {Array} The list of files in this directory and subdirs
43 */
44 static walkDirSync(dir: any, filelist?: any[]): any[];
45 /**
46 * find matching files based on the given path or glob
47 *
48 * @param {string} patterns - glob pattern(s) or relative path
49 * @param {boolean} [isGlob] - pass true to treat the path as a glob
50 * @param {Object} [globOptions] - options to pass to globby
51 * @returns {Array<string>} files
52 */
53 static findMatchingFiles(patterns: string | Array<string>, {isGlob, globOptions}: {
54 isGlob: boolean;
55 globOptions: Object;
56 }): Array<string>;
57 /**
58 * Get an element from the configuration.
59 * Can be both a leaf of the configuration, or an intermediate path. In the latter case it will return
60 * an object with all the configs under that path.
61 * It will throw an exception if the key doesn't exist.
62 *
63 * @param {string} key The key of the config we want
64 * @param {*} defaultValue A default value to use if the key doesn't exist
65 * @return {*} The requested configuration
66 * @throws {Error} If the given key doesn't exist and a default value is not provided
67 * @see {@link Context.hasConfig}
68 */
69 getConfig(key: string, defaultValue?: any): any;
70 /**
71 * Indicates whether a given key exists in the configuration
72 * @param key
73 * @return {*}
74 */
75 hasConfig(key: string): boolean;
76 addObjectNameToGroup(groupName: string, objectName: string): void;
77 getGroupObjectNames(groupName: string): string[];
78 getObjectByName(beanName: string): Promise<any>;
79 getObjectByType(className: string): Promise<any>;
80 getObjectsByType(className: string): Promise<any[]>;
81 getObjectsByGroup(groupName: string): Promise<any[]>;
82 getDefinitionByName(objectName: string): ObjectDefinition<any>;
83 getDefinitionByType(className: string): ObjectDefinition<any>;
84 getDefinitionsByType(className: string, failOnMissing?: boolean): Array<ObjectDefinition<any>>;
85 getDefinitionsByGroup(groupName: string): Array<ObjectDefinition<any>>;
86 applyObjectDefinitionModifiers(): void;
87}