UNPKG

12 kBTypeScriptView Raw
1import { Application, Binding, BindingFilter, BindingFromClassOptions, BindingScope, Component, Constructor, Context, MixinTarget } from '@loopback/core';
2import { Bootable, Booter, BootOptions, InstanceWithBooters } from '../types';
3export { Binding };
4/**
5 * Mixin for @loopback/boot. This Mixin provides the following:
6 * - Implements the Bootable Interface as follows.
7 * - Add a `projectRoot` property to the Class
8 * - Adds an optional `bootOptions` property to the Class that can be used to
9 * store the Booter conventions.
10 * - Adds the `BootComponent` to the Class (which binds the Bootstrapper and default Booters)
11 * - Provides the `boot()` convenience method to call Bootstrapper.boot()
12 * - Provides the `booter()` convenience method to bind a Booter(s) to the Application
13 * - Override `component()` to call `mountComponentBooters`
14 * - Adds `mountComponentBooters` which binds Booters to the application from `component.booters[]`
15 *
16 * @param superClass - Application class
17 * @returns A new class that extends the super class with boot related methods
18 *
19 * @typeParam T - Type of the application class as the target for the mixin
20 */
21export declare function BootMixin<T extends MixinTarget<Application>>(superClass: T): {
22 new (...args: any[]): {
23 projectRoot: string;
24 bootOptions?: BootOptions | undefined;
25 booted: boolean;
26 /**
27 * Override to detect and warn about starting without booting.
28 */
29 start(): Promise<void>;
30 /**
31 * Convenience method to call bootstrapper.boot() by resolving bootstrapper
32 */
33 boot(): Promise<void>;
34 /**
35 * Given a N number of Booter Classes, this method binds them using the
36 * prefix and tag expected by the Bootstrapper.
37 *
38 * @param booterCls - Booter classes to bind to the Application
39 *
40 * @example
41 * ```ts
42 * app.booters(MyBooter, MyOtherBooter)
43 * ```
44 */
45 booters(...booterCls: Constructor<Booter>[]): Binding[];
46 /**
47 * Register a booter to boot a sub-application. See
48 * {@link createComponentApplicationBooterBinding} for more details.
49 *
50 * @param subApp - A sub-application with artifacts to be booted
51 * @param filter - A binding filter to select what bindings from the sub
52 * application should be added to the main application.
53 */
54 applicationBooter(subApp: Application & Bootable, filter?: BindingFilter): Binding<Booter>;
55 /**
56 * Override to ensure any Booter's on a Component are also mounted.
57 *
58 * @param component - The component to add.
59 *
60 * @example
61 * ```ts
62 *
63 * export class ProductComponent {
64 * booters = [ControllerBooter, RepositoryBooter];
65 * providers = {
66 * [AUTHENTICATION_STRATEGY]: AuthStrategy,
67 * [AUTHORIZATION_ROLE]: Role,
68 * };
69 * };
70 *
71 * app.component(ProductComponent);
72 * ```
73 */
74 component<C extends Component = Component>(componentCtor: Constructor<C>, nameOrOptions?: string | BindingFromClassOptions): Binding<C>;
75 /**
76 * Get an instance of a component and mount all it's
77 * booters. This function is intended to be used internally
78 * by component()
79 *
80 * @param component - The component to mount booters of
81 */
82 mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void;
83 readonly options: import("@loopback/core").ApplicationConfig;
84 readonly state: string;
85 controller: <T_1>(controllerCtor: import("@loopback/core").ControllerClass<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>;
86 server: <T_2 extends import("@loopback/core").Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
87 servers: <T_3 extends import("@loopback/core").Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
88 getServer: <T_4 extends import("@loopback/core").Server>(target: string | Constructor<T_4>) => Promise<T_4>;
89 init: () => Promise<void>;
90 onInit: (fn: () => import("@loopback/core").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>;
91 onStart: (fn: () => import("@loopback/core").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>;
92 stop: () => Promise<void>;
93 onStop: (fn: () => import("@loopback/core").ValueOrPromise<void>) => Binding<import("@loopback/core").LifeCycleObserver>;
94 setMetadata: (metadata: import("@loopback/core").ApplicationMetadata) => void;
95 lifeCycleObserver: <T_5 extends import("@loopback/core").LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
96 service: <S>(cls: import("@loopback/core").ServiceOrProviderClass<S>, nameOrOptions?: string | import("@loopback/core").ServiceOptions | undefined) => Binding<S>;
97 interceptor: (interceptor: import("@loopback/core").Interceptor | Constructor<import("@loopback/core").Provider<import("@loopback/core").Interceptor>>, nameOrOptions?: string | import("@loopback/core").InterceptorBindingOptions | undefined) => Binding<import("@loopback/core").Interceptor>;
98 readonly name: string;
99 readonly subscriptionManager: import("@loopback/core").ContextSubscriptionManager;
100 scope: BindingScope;
101 readonly parent: Context | undefined;
102 emitEvent: <T_6 extends import("@loopback/core").ContextEvent>(type: string, event: T_6) => void;
103 emitError: (err: unknown) => void;
104 bind: <ValueType = any>(key: import("@loopback/core").BindingAddress<ValueType>) => Binding<ValueType>;
105 add: (binding: Binding<unknown>) => Application;
106 configure: <ConfigValueType = any>(key?: import("@loopback/core").BindingAddress<unknown> | undefined) => Binding<ConfigValueType>;
107 getConfigAsValueOrPromise: <ConfigValueType_1>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => import("@loopback/core").ValueOrPromise<ConfigValueType_1 | undefined>;
108 getConfig: <ConfigValueType_2>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
109 getConfigSync: <ConfigValueType_3>(key: import("@loopback/core").BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: import("@loopback/core").ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
110 unbind: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
111 subscribe: (observer: import("@loopback/core").ContextEventObserver) => import("@loopback/core").Subscription;
112 unsubscribe: (observer: import("@loopback/core").ContextEventObserver) => boolean;
113 close: () => void;
114 isSubscribed: (observer: import("@loopback/core").ContextObserver) => boolean;
115 createView: <T_7 = unknown>(filter: BindingFilter, comparator?: import("@loopback/core").BindingComparator | undefined, options?: Omit<import("@loopback/core").ResolutionOptions, "session"> | undefined) => import("@loopback/core").ContextView<T_7>;
116 contains: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
117 isBound: (key: import("@loopback/core").BindingAddress<unknown>) => boolean;
118 getOwnerContext: (keyOrBinding: Readonly<Binding<unknown>> | import("@loopback/core").BindingAddress<unknown>) => Context | undefined;
119 getScopedContext: (scope: BindingScope.APPLICATION | BindingScope.SERVER | BindingScope.REQUEST) => Context | undefined;
120 getResolutionContext: (binding: Readonly<Binding<unknown>>) => Context | undefined;
121 isVisibleTo: (ctx: Context) => boolean;
122 find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
123 findByTag: <ValueType_2 = any>(tagFilter: RegExp | import("@loopback/core").BindingTag) => Readonly<Binding<ValueType_2>>[];
124 get: {
125 <ValueType_3>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_3>, session?: import("@loopback/core").ResolutionSession | undefined): Promise<ValueType_3>;
126 <ValueType_4>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_4>, options: import("@loopback/core").ResolutionOptions): Promise<ValueType_4 | undefined>;
127 };
128 getSync: {
129 <ValueType_5>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_5>, session?: import("@loopback/core").ResolutionSession | undefined): ValueType_5;
130 <ValueType_6>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_6>, options?: import("@loopback/core").ResolutionOptions | undefined): ValueType_6 | undefined;
131 };
132 getBinding: {
133 <ValueType_7 = any>(key: import("@loopback/core").BindingAddress<ValueType_7>): Binding<ValueType_7>;
134 <ValueType_8>(key: import("@loopback/core").BindingAddress<ValueType_8>, options?: {
135 optional?: boolean | undefined;
136 } | undefined): Binding<ValueType_8> | undefined;
137 };
138 findOrCreateBinding: <T_8>(key: import("@loopback/core").BindingAddress<T_8>, policy?: import("@loopback/core").BindingCreationPolicy | undefined) => Binding<T_8>;
139 getValueOrPromise: <ValueType_9>(keyWithPath: import("@loopback/core").BindingAddress<ValueType_9>, optionsOrSession?: import("@loopback/core").ResolutionOptionsOrSession | undefined) => import("@loopback/core").ValueOrPromise<ValueType_9 | undefined>;
140 toJSON: () => import("@loopback/core").JSONObject;
141 inspect: (options?: import("@loopback/core").ContextInspectOptions | undefined) => import("@loopback/core").JSONObject;
142 on: {
143 (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): Application;
144 (event: string | symbol, listener: (...args: any[]) => void): Application;
145 };
146 once: {
147 (eventName: "bind" | "unbind", listener: import("@loopback/core").ContextEventListener): Application;
148 (event: string | symbol, listener: (...args: any[]) => void): Application;
149 };
150 addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
151 removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
152 off: (event: string | symbol, listener: (...args: any[]) => void) => Application;
153 removeAllListeners: (event?: string | symbol | undefined) => Application;
154 setMaxListeners: (n: number) => Application;
155 getMaxListeners: () => number;
156 listeners: (event: string | symbol) => Function[];
157 rawListeners: (event: string | symbol) => Function[];
158 emit: (event: string | symbol, ...args: any[]) => boolean;
159 listenerCount: (event: string | symbol) => number;
160 prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
161 prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
162 eventNames: () => (string | symbol)[];
163 };
164} & T;
165/**
166 * Method which binds a given Booter to a given Context with the Prefix and
167 * Tags expected by the Bootstrapper
168 *
169 * @param ctx - The Context to bind the Booter Class
170 * @param booterCls - Booter class to be bound
171 */
172export declare function bindBooter(ctx: Context, booterCls: Constructor<Booter>): Binding;
173export declare const _bindBooter: typeof bindBooter;