@ima/core
Version:
IMA.js framework for isomorphic javascript application
138 lines • 5.74 kB
TypeScript
import { Response as ExpressResponse, Request as ExpressRequest } from 'express';
import { PartialDeep } from 'type-fest';
import { DictionaryConfig } from '.';
import { AppSettings, Settings } from './boot';
import { Namespace } from './Namespace';
import { BindingState } from './oc/BindingState';
import { ObjectContainer } from './oc/ObjectContainer';
import { Router } from './router/Router';
import { GlobalImaObject, UnknownParameters } from './types';
export type InitBindFunction = (ns: Namespace, oc: ObjectContainer, config: Required<BootConfig>['bind'], state: BindingState) => void;
export type InitRoutesFunction = (ns: Namespace, oc: ObjectContainer, routes: UnknownParameters | undefined, router: Router) => void;
export type InitServicesFunction = (ns: Namespace, oc: ObjectContainer, config: BootConfig['services']) => void;
export type InitSettingsFunction = (ns: Namespace, oc: ObjectContainer, config: BootConfig['settings']) => AppSettings;
export type PluginInitBindFunction = (ns: Namespace, oc: ObjectContainer, config: Required<BootConfig>['bind'], isDynamicallyLoaded: boolean, name?: string) => void;
export type PluginInitServicesFunction = (ns: Namespace, oc: ObjectContainer, config: BootConfig['services'], isDynamicallyLoaded: boolean) => void;
export type PluginInitSettingsFunction = (ns: Namespace, oc: ObjectContainer, config: BootConfig['settings'], isDynamicallyLoaded: boolean) => PartialDeep<AppSettings>;
export interface InitPluginConfig {
initServices?: PluginInitServicesFunction;
initBind?: PluginInitBindFunction;
initSettings?: PluginInitSettingsFunction;
}
export interface InitAppConfig {
initBindApp: InitBindFunction;
initRoutes: InitRoutesFunction;
initServicesApp: InitServicesFunction;
initSettings: InitSettingsFunction;
}
export interface InitImaConfig {
initBindIma: InitBindFunction;
initServicesIma: InitServicesFunction;
}
export type BootSettings = Pick<GlobalImaObject, '$Version' | '$Debug' | '$Env' | '$Version' | '$App' | '$Protocol' | '$Language' | '$Host' | '$Path' | '$Root' | '$LanguagePartPath'>;
export interface BootServices {
response: ExpressResponse | null;
request: ExpressRequest | null;
$IMA: Window['$IMA'];
dictionary: DictionaryConfig;
router: {
$Protocol: GlobalImaObject['$Protocol'];
$Host: GlobalImaObject['$Host'];
$Path: GlobalImaObject['$Path'];
$Root: GlobalImaObject['$Root'];
$LanguagePartPath: GlobalImaObject['$LanguagePartPath'];
};
}
export interface BootConfig extends InitImaConfig, InitAppConfig {
routes?: UnknownParameters;
bind?: Settings & BootSettings;
plugins: {
name: string;
plugin: InitPluginConfig;
}[];
services: BootServices;
settings: BootSettings;
}
/**
* Application bootstrap used to initialize the environment and the application
* itself.
*/
export declare class Bootstrap {
protected _oc: ObjectContainer;
protected _config: BootConfig;
/**
* Initializes the bootstrap.
*
* @param oc The application's object container to use
* for managing dependencies.
*/
constructor(oc: ObjectContainer);
/**
* Initializes the application by running the bootstrap sequence. The
* sequence initializes the components of the application in the following
* order:
* - application settings
* - constants, service providers and class dependencies configuration
* - services
* - UI components
* - routing
*
* @param config The application environment
* configuration for the current environment.
*/
run(config: BootConfig): void;
/**
* Initializes dynamically loaded plugin. This is explicitly called from
* within the Plugin Loader instance.
*
* @param name Plugin name.
* @param plugin Plugin interface (object with init functions).
*/
initPlugin(name: string, plugin?: InitPluginConfig): void;
/**
* Initializes the application settings. The method loads the settings for
* all environments and then picks the settings for the current environment.
*
* The method also handles using the values in the production environment
* as default values for configuration items in other environments.
*/
_initSettings(): void;
/**
* Initializes dynamically loaded plugin settings (if the init
* function is provided). The settings are merged into the application
* the same way as with non-dynamic import, meaning the app setting overrides
* are prioritized over the default plugin settings.
*
* @param name Plugin name.
* @param plugin Plugin interface (object with init functions).
*/
_initPluginSettings(name: string, plugin: InitPluginConfig): void;
/**
* Binds the constants, service providers and class dependencies to the
* object container.
*/
_bindDependencies(): void;
/**
* Binds the constants, service providers and class dependencies to the
* object container for dynamically imported plugins.
*
* @param name Plugin name.
* @param plugin Plugin interface (object with init functions).
*/
_bindPluginDependencies(name: string, plugin: InitPluginConfig): void;
/**
* Initializes the routes.
*/
_initRoutes(): void;
/**
* Initializes the basic application services.
*/
_initServices(): void;
/**
* Service initialization for the dynamically loaded plugins.
*
* @param plugin Plugin interface (object with init functions).
*/
_initPluginServices(plugin: InitPluginConfig): void;
}
//# sourceMappingURL=Bootstrap.d.ts.map