import { interfaces as inversifyInterfaces } from "inversify"; export interface ExecutableExtension { execute(): any; } export interface Message { componentInterface: symbol; [key: string]: any; } export interface MessageHandler { (message: Message): void; } export interface MessageBus { on(componentInterface: symbol, handler: MessageHandler): any; emit(message: Message): any; } export declare namespace Hooks { interface PipeFactory { (componentInterface: symbol): Hooks.Pipe; } enum ExecutionMode { Filter = 0, ResultSet = 1 } interface ContinuationFunction { (result?: any): void; } /** * Function which intercepts into a given workflow. Based on execution mode and return of the hook, the workflow might be interrupted. * @param {ExecutionMode} mode execution mode of this hook. If set to filter, your hook function is able to intercept the workflow * @param args all additional arguments passed to the hook function * @return {Promise | HookResult | boolean} true / false if the workflow should be interrupted, or HookResult for more complex responses */ interface Hook { (mode: ExecutionMode, ...args: any[]): Promise | HookResult | boolean; } /** Possible result set of your hook function */ interface HookResult { /** Set to false to intercept the workflo */ success: boolean; result?: any; } interface ExecutionResult { hook: Hook; result: any; } interface ExecutionSummary { /** If all hooks were successfully executed */ success: boolean; /** List of successfully executed hooks */ successfulHooks: ExecutionResult[]; /** List of failed hooks */ failedHooks: ExecutionResult[]; /** Arguments passed to hook functions */ arguments: any[]; } interface Pipe { /** List containing all available hooks */ hooks: Hook[]; /** * withArguments() * Returns a new HookPipe based on this one, but with given arguments * Implements immutable pattern */ withArguments(...args: any[]): Pipe; /** * runAsFilter() * Runs all hooks in this pipe as filter. If one hook fails, all following hooks are not executed anymore. */ runAsFilter(): Promise; /** * runWithResultset() * Runs all hooks regardless of each's return value. */ runWithResultset(): Promise; } } export interface Component { readonly name: string; readonly interfaces: InterfaceDescriptor; getInterface(name: string): symbol; configuration: Configuration; addConfiguration(configuration: Partial): void; } export interface ComponentBinder { /** * Use this method if you want to bind a service locally. * @param serviceSymbol:symbol Use a (more or less) secret symbol which is not exposed to * the component registry (in contrast to component interfaces). Only your component should be * able to read it. */ bindLocalService(serviceIdentifier: symbol): inversifyInterfaces.BindingToSyntax; /** * Same as bindLocalService(), but you don't need a symbol, use the class itself as identifier and bind directly to it */ bindLocalServiceToSelf(service: { new (...args: any[]): any; }): inversifyInterfaces.BindingInWhenOnSyntax; /** * Use this to expose a service to the whole environment. * @param serviceName Your service will be available via componentName:serviceName */ bindGlobalService(serviceName: string): inversifyInterfaces.BindingToSyntax; bindExtension(componentInterface: symbol): inversifyInterfaces.BindingToSyntax; bindExecutable(componentInterface: symbol, extensionClass: { new (...args: any[]): ExecutableExtension; }): inversifyInterfaces.BindingWhenOnSyntax; } export interface ComponentDescriptor { name: string; interfaces?: InterfaceDescriptor; defaultConfiguration?: OptionalConfiguration | (() => OptionalConfiguration); bindings: BindingDescriptor; } export interface LookupService { lookup(componentName: string): Component; isRegistered(componentName: string): boolean; } export interface ComponentRegistry extends LookupService { readonly registeredComponents: { [name: string]: Component; }; add(component: Component): void; addFromDescriptor(descriptor: ComponentDescriptor): void; executeBinding(componentName: string, container: BindableContainer, scope?: string, ...args: any[]): void; autobind(container: BindableContainer, except?: string[], scope?: string, ...args: any[]): void; getBinder(componentName: string, container: BindableContainer): ComponentBinder; } export interface MainApplication { execute(container: Container): ExecuteReturn; } export interface Container { readonly componentRegistry: ComponentRegistry; readonly inversifyInstance: inversifyInterfaces.Container; setMainApplication(app: MainApplication): void; runMain(): ReturnType; } export interface BindableContainer { bind(serviceIdentifier: inversifyInterfaces.ServiceIdentifier): inversifyInterfaces.BindingToSyntax; } export interface BindingDescriptor { root: ScopedBindingDescriptor; [name: string]: ScopedBindingDescriptor; } export interface ScopedBindingDescriptor { (bindService: ComponentBinder, lookupService: LookupService, inversifyInstance: inversifyInterfaces.Container, ...args: any[]): void; } export interface InterfaceDescriptor { [name: string]: symbol; }