UNPKG

@loopback/boot

Version:

A collection of Booters for LoopBack 4 Applications

175 lines (174 loc) • 11.9 kB
import { Application, Binding, BindingFilter, BindingFromClassOptions, BindingScope, Component, Constructor, Context, MixinTarget } from '@loopback/core'; import { Bootable, Booter, BootOptions, InstanceWithBooters } from '../types'; export { Binding }; /** * Mixin for @loopback/boot. This Mixin provides the following: * - Implements the Bootable Interface as follows. * - Add a `projectRoot` property to the Class * - Adds an optional `bootOptions` property to the Class that can be used to * store the Booter conventions. * - Adds the `BootComponent` to the Class (which binds the Bootstrapper and default Booters) * - Provides the `boot()` convenience method to call Bootstrapper.boot() * - Provides the `booter()` convenience method to bind a Booter(s) to the Application * - Override `component()` to call `mountComponentBooters` * - Adds `mountComponentBooters` which binds Booters to the application from `component.booters[]` * * @param superClass - Application class * @returns A new class that extends the super class with boot related methods * * @typeParam T - Type of the application class as the target for the mixin */ export declare function BootMixin<T extends MixinTarget<Application>>(superClass: T): { new (...args: any[]): { projectRoot: string; bootOptions?: BootOptions; booted: boolean; /** * Override to detect and warn about starting without booting. */ start(): Promise<void>; /** * Convenience method to call bootstrapper.boot() by resolving bootstrapper */ boot(): Promise<void>; /** * Given a N number of Booter Classes, this method binds them using the * prefix and tag expected by the Bootstrapper. * * @param booterCls - Booter classes to bind to the Application * * @example * ```ts * app.booters(MyBooter, MyOtherBooter) * ``` */ booters(...booterCls: Constructor<Booter>[]): Binding[]; /** * Register a booter to boot a sub-application. See * {@link createComponentApplicationBooterBinding} for more details. * * @param subApp - A sub-application with artifacts to be booted * @param filter - A binding filter to select what bindings from the sub * application should be added to the main application. */ applicationBooter(subApp: Application & Bootable, filter?: BindingFilter): Binding<Booter>; /** * Override to ensure any Booter's on a Component are also mounted. * * @param component - The component to add. * * @example * ```ts * * export class ProductComponent { * booters = [ControllerBooter, RepositoryBooter]; * providers = { * [AUTHENTICATION_STRATEGY]: AuthStrategy, * [AUTHORIZATION_ROLE]: Role, * }; * }; * * app.component(ProductComponent); * ``` */ component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions): Binding<C>; /** * Get an instance of a component and mount all it's * booters. This function is intended to be used internally * by component() * * @param component - The component to mount booters of */ mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void; readonly name: string; readonly subscriptionManager: import("@loopback/context").ContextSubscriptionManager; scope: BindingScope; readonly parent: Context | undefined; emitEvent: <T_1 extends import("@loopback/context").ContextEvent>(type: string, event: T_1) => void; emitError: (err: unknown) => void; bind: <ValueType = any>(key: import("@loopback/context").BindingAddress<ValueType>) => Binding<ValueType>; add: (binding: Binding<unknown>) => Application; configure: <ConfigValueType = any>(key?: import("@loopback/context").BindingAddress) => Binding<ConfigValueType>; getConfigAsValueOrPromise: <ConfigValueType>(key: import("@loopback/context").BindingAddress, propertyPath?: string, resolutionOptions?: import("@loopback/context").ResolutionOptions) => import("@loopback/context").ValueOrPromise<ConfigValueType | undefined>; getConfig: <ConfigValueType>(key: import("@loopback/context").BindingAddress, propertyPath?: string, resolutionOptions?: import("@loopback/context").ResolutionOptions) => Promise<ConfigValueType | undefined>; getConfigSync: <ConfigValueType>(key: import("@loopback/context").BindingAddress, propertyPath?: string, resolutionOptions?: import("@loopback/context").ResolutionOptions) => ConfigValueType | undefined; unbind: (key: import("@loopback/context").BindingAddress) => boolean; subscribe: (observer: import("@loopback/context").ContextEventObserver) => import("@loopback/context").Subscription; unsubscribe: (observer: import("@loopback/context").ContextEventObserver) => boolean; close: () => void; isSubscribed: (observer: import("@loopback/context").ContextObserver) => boolean; createView: <T_1 = unknown>(filter: BindingFilter, comparator?: import("@loopback/context").BindingComparator, options?: Omit<import("@loopback/context").ResolutionOptions, 'session'>) => import("@loopback/context").ContextView<T_1>; contains: (key: import("@loopback/context").BindingAddress) => boolean; isBound: (key: import("@loopback/context").BindingAddress) => boolean; getOwnerContext: (keyOrBinding: import("@loopback/context").BindingAddress | Readonly<Binding<unknown>>) => Context | undefined; getScopedContext: (scope: BindingScope.APPLICATION | BindingScope.SERVER | BindingScope.REQUEST) => Context | undefined; getResolutionContext: (binding: Readonly<Binding<unknown>>) => Context | undefined; isVisibleTo: (ctx: Context) => boolean; find: <ValueType = any>(pattern?: string | RegExp | BindingFilter) => Readonly<Binding<ValueType>>[]; findByTag: <ValueType = any>(tagFilter: import("@loopback/context").BindingTag | RegExp) => Readonly<Binding<ValueType>>[]; get: { <ValueType>(keyWithPath: import("@loopback/context").BindingAddress<ValueType>, session?: import("@loopback/context").ResolutionSession): Promise<ValueType>; <ValueType>(keyWithPath: import("@loopback/context").BindingAddress<ValueType>, options: import("@loopback/context").ResolutionOptions): Promise<ValueType | undefined>; }; getSync: { <ValueType>(keyWithPath: import("@loopback/context").BindingAddress<ValueType>, session?: import("@loopback/context").ResolutionSession): ValueType; <ValueType>(keyWithPath: import("@loopback/context").BindingAddress<ValueType>, options?: import("@loopback/context").ResolutionOptions): ValueType | undefined; }; getBinding: { <ValueType = any>(key: import("@loopback/context").BindingAddress<ValueType>): Binding<ValueType>; <ValueType>(key: import("@loopback/context").BindingAddress<ValueType>, options?: { optional?: boolean; }): Binding<ValueType> | undefined; }; findOrCreateBinding: <T_1>(key: import("@loopback/context").BindingAddress<T_1>, policy?: import("@loopback/context").BindingCreationPolicy) => Binding<T_1>; getValueOrPromise: <ValueType>(keyWithPath: import("@loopback/context").BindingAddress<ValueType>, optionsOrSession?: import("@loopback/context").ResolutionOptionsOrSession) => import("@loopback/context").ValueOrPromise<ValueType | undefined>; toJSON: () => import("@loopback/context").JSONObject; inspect: (options?: import("@loopback/context").ContextInspectOptions) => import("@loopback/context").JSONObject; on: { (eventName: 'bind' | 'unbind', listener: import("@loopback/context").ContextEventListener): Application; (event: string | symbol, listener: (...args: any[]) => void): Application; }; once: { (eventName: 'bind' | 'unbind', listener: import("@loopback/context").ContextEventListener): Application; (event: string | symbol, listener: (...args: any[]) => void): Application; }; readonly options: import("@loopback/core").ApplicationConfig; readonly state: string; controller: <T_1>(controllerCtor: import("@loopback/core").ControllerClass<T_1>, nameOrOptions?: string | BindingFromClassOptions) => Binding<T_1>; server: <T_1 extends import("@loopback/core").Server>(ctor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions) => Binding<T_1>; servers: <T_1 extends import("@loopback/core").Server>(ctors: Constructor<T_1>[]) => Binding[]; getServer: <T_1 extends import("@loopback/core").Server>(target: Constructor<T_1> | string) => Promise<T_1>; init: () => Promise<void>; onInit: (fn: () => import("@loopback/context").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>; onStart: (fn: () => import("@loopback/context").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>; stop: () => Promise<void>; onStop: (fn: () => import("@loopback/context").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>; setMetadata: (metadata: import("@loopback/core").ApplicationMetadata) => void; lifeCycleObserver: <T_1 extends import("@loopback/core").LifeCycleObserver>(ctor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions) => Binding<T_1>; service: <S>(cls: import("@loopback/core").ServiceOrProviderClass<S>, nameOrOptions?: string | import("@loopback/core").ServiceOptions) => Binding<S>; interceptor: (interceptor: import("@loopback/context").Interceptor | Constructor<import("@loopback/context").Provider<import("@loopback/context").Interceptor>>, nameOrOptions?: string | import("@loopback/context").InterceptorBindingOptions) => Binding<import("@loopback/context").Interceptor>; [EventEmitter.captureRejectionSymbol]?: (<K>(error: Error, event: string | symbol, ...args: any[]) => void) | undefined; addListener: <K>(eventName: string | symbol, listener: (...args: any[]) => void) => Application; removeListener: <K>(eventName: string | symbol, listener: (...args: any[]) => void) => Application; off: <K>(eventName: string | symbol, listener: (...args: any[]) => void) => Application; removeAllListeners: (eventName?: string | symbol | undefined) => Application; setMaxListeners: (n: number) => Application; getMaxListeners: () => number; listeners: <K>(eventName: string | symbol) => Function[]; rawListeners: <K>(eventName: string | symbol) => Function[]; emit: <K>(eventName: string | symbol, ...args: any[]) => boolean; listenerCount: <K>(eventName: string | symbol, listener?: Function | undefined) => number; prependListener: <K>(eventName: string | symbol, listener: (...args: any[]) => void) => Application; prependOnceListener: <K>(eventName: string | symbol, listener: (...args: any[]) => void) => Application; eventNames: () => (string | symbol)[]; }; } & T; /** * Method which binds a given Booter to a given Context with the Prefix and * Tags expected by the Bootstrapper * * @param ctx - The Context to bind the Booter Class * @param booterCls - Booter class to be bound */ export declare function bindBooter(ctx: Context, booterCls: Constructor<Booter>): Binding; export declare const _bindBooter: typeof bindBooter;